Initializable decorator improvements

This commit is contained in:
sanex3339
2018-02-09 01:55:40 +03:00
parent e44c160286
commit eb68e7ea57
4 changed files with 61 additions and 9998 deletions
@@ -50,12 +50,61 @@ describe('@initializable', () => {
foo.bar();
};
it('should throws an error if `initialize` method wasn\'t called first', () => {
it('shouldn\'t throw an error if `initialize` method was called first', () => {
assert.doesNotThrow(testFunc, /Class should be initialized/);
});
});
describe('variant #2: `initialize` method wasn\'t called first', () => {
describe('variant #2: other method was called inside `initialize` method with initialization of the property', () => {
const testFunc: () => void = () => {
class Foo {
@initializable()
public property!: string;
public initialize (property: string): void {
this.innerInitialize(property);
}
public innerInitialize (property: string): void {
this.property = property;
}
}
const foo: Foo = new Foo();
foo.initialize('baz');
};
it('shouldn\'t throw an error if other method was called inside `initialize` method', () => {
assert.doesNotThrow(testFunc, /Class should be initialized/);
});
});
describe('variant #3: other method was called inside `initialize` method without initialization of the property', () => {
const testFunc: () => void = () => {
class Foo {
@initializable()
public property!: string;
public initialize (property: string): void {
this.innerInitialize(property);
}
public innerInitialize (property: string): void {
}
}
const foo: Foo = new Foo();
foo.initialize('baz');
};
it('should throws an error if other method was called inside `initialize` method without initialization of the property', () => {
assert.throws(testFunc, /Property `property` is not initialized/);
});
});
describe('variant #4: `initialize` method wasn\'t called first', () => {
const testFunc: () => void = () => {
class Foo {
@initializable()
@@ -79,7 +128,7 @@ describe('@initializable', () => {
});
});
describe('variant #3: `initialize` method wasn\'t called', () => {
describe('variant #5: `initialize` method wasn\'t called', () => {
const testFunc: () => void = () => {
class Foo {
@initializable()