mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Initializable decorator improvements
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user