Skip to content

Commit

Permalink
Merge pull request #6 from dimasmds/2.0.5
Browse files Browse the repository at this point in the history
2.0.5
  • Loading branch information
dimasmds authored Dec 20, 2021
2 parents bdb2346 + 9d8e821 commit c927426
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.id-ID.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ container.register({ Class: Engine });

### container.destroyInstance(key)
Setiap class yang didaftarkan diakses, ia akan membuat instance di dalam properti `container.instances[key].INSTANCE`.
Fungsi `container.deleteInstance(key)` digunakan untuk menghapus instance dari class untuk menghapus ruang penggunaan memory.
Fungsi `container.destroyInstance(key)` digunakan untuk menghapus instance dari class untuk menghapus ruang penggunaan memory.

Example:

Expand Down
10 changes: 5 additions & 5 deletions src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Container {

private static verifyParameterOption(optionParameter: ParameterOption) {
if (typeof optionParameter !== 'object' || Array.isArray(optionParameter)) {
throw new Error('parameter should be a parameter option object');
throw new Error('parameter should be a ParameterOption object');
}

const keys = Object.keys(optionParameter);
Expand Down Expand Up @@ -80,15 +80,15 @@ export class Container {

dependencies.forEach((dependency) => {
if (typeof dependency !== 'object' || Array.isArray(dependency)) {
throw new Error('dependencies item should be a dependency object');
throw new Error('dependencies item should be a Dependency object');
}

const keys = Object.keys(dependency);
const allowedProps = ['name', 'concrete', 'internal'];
const unknownProps = keys.filter((key) => !allowedProps.includes(key));

if (unknownProps.length) {
throw new Error(`${unknownProps.join(', ')} is not allowed in dependency object`);
throw new Error(`${unknownProps.join(', ')} is not allowed in Dependency object`);
}

if (!dependency.name) {
Expand Down Expand Up @@ -172,7 +172,7 @@ export class Container {
const instance = this.instances[key];

if (!instance) {
throw new Error('instance not found');
throw new Error(`${key} instance not found`);
}

if (instance.INSTANCE instanceof instance.Class) {
Expand All @@ -188,7 +188,7 @@ export class Container {

public destroyInstance(key: string) {
if (!this.instances[key]) {
throw new Error('not found instance to be destroy');
throw new Error(`Cannot destroy instance with key ${key}. Because it is not exist`);
}

delete this.instances[key].INSTANCE;
Expand Down
10 changes: 5 additions & 5 deletions src/__test__/Container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Container', () => {
},
];

expect(() => new Container(instanceOptions)).toThrowError('parameter should be a parameter option object');
expect(() => new Container(instanceOptions)).toThrowError('parameter should be a ParameterOption object');
});

it('should throw error when parameter is contain unknown property', () => {
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('Container', () => {
},
];

expect(() => new Container(instanceOptions)).toThrowError('dependencies item should be a dependency object');
expect(() => new Container(instanceOptions)).toThrowError('dependencies item should be a Dependency object');
});

it('should throw error when dependency is contain unknown property', () => {
Expand All @@ -153,7 +153,7 @@ describe('Container', () => {
},
];

expect(() => new Container(instanceOptions)).toThrowError('unknownA, unknownB is not allowed in dependency object');
expect(() => new Container(instanceOptions)).toThrowError('unknownA, unknownB is not allowed in Dependency object');
});

it('should throw error when dependency is not contain name property', () => {
Expand Down Expand Up @@ -635,7 +635,7 @@ describe('Container', () => {

it('should throw error when instance not found', () => {
expect(() => container.getInstance('abc'))
.toThrowError('instance not found');
.toThrow('abc instance not found');
});

it('should only create one instance (singleton)', () => {
Expand Down Expand Up @@ -683,7 +683,7 @@ describe('Container', () => {

it('should throw error when instance is not found', () => {
expect(() => container.destroyInstance('not_found'))
.toThrowError('not found instance to be destroy');
.toThrowError('Cannot destroy instance with key not_found. Because it is not exist');
});

it('should delete active instance correctly', () => {
Expand Down

0 comments on commit c927426

Please sign in to comment.