Skip to content

Commit

Permalink
BREAKING CHANGE: Rename TestContainer -> TestIoCContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodluckhf committed Jul 3, 2019
1 parent bc049f0 commit 58603e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ http.listen(port);
### Testing
We provide a comfortable way for testing
```javascript
import {TestContainer} from '@ukitgroup/ioc';
import { TestIoCContainer } from '@ukitgroup/ioc';
describe('Unit test', () => {
const ctx = {}

beforeEach(() => {
ctx.container = TestContainer.createTestModule([
ctx.container = TestIoCContainer.createTestModule([
//... providers definition with mocks
])
ctx.container.compile();
Expand All @@ -222,5 +222,5 @@ More examples you can find in [integration tests](https://github.com/Goodluckhf/

### TODO:
* support decorators with typescript
* TestContainer for integration tests
* TestIoCContainer for integration tests
* Get public providers by tag
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export class IoCContainer extends DIContainer {
}
}

export { TestContainer } from './test-container';
export { TestIoCContainer } from './test-ioc-container';
17 changes: 13 additions & 4 deletions src/integration-tests/test-container.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'reflect-metadata';
import { TestContainer } from '../test-container';
import { TestIoCContainer } from '../test-ioc-container';
import { ManifestInterface } from '../dto/manifest.interface';

class ServiceA {}

describe.skip('TestContainer', () => {
it('should override providers', () => {
describe('TestContainer', () => {
it.skip('should override providers', () => {
const diManifest: ManifestInterface = {
moduleName: 'module',
providers: [
Expand All @@ -17,7 +17,7 @@ describe.skip('TestContainer', () => {
],
};

const testContainerAdapter = new TestContainer([diManifest]);
const testContainerAdapter = new TestIoCContainer([diManifest]);
// @ts-ignore
testContainerAdapter.override([
{ token: 'ServiceA', useValue: 10, isPublic: true },
Expand All @@ -27,4 +27,13 @@ describe.skip('TestContainer', () => {
const serviceA = testContainerAdapter.get('ServiceA');
expect(serviceA).toEqual(10);
});

it('can get provider without module', () => {
const testContainer = TestIoCContainer.createTestModule([
{ isPublic: true, token: 'testToken', useValue: 10 },
]);

testContainer.compile();
expect(testContainer.get('testToken')).toBe(10);
});
});
4 changes: 2 additions & 2 deletions src/test-container.ts → src/test-ioc-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ManifestTransformer } from './manifest-transformer';

const testModuleName = 'testModule';

class TestContainer {
class TestIoCContainer {
private container: Container;

public constructor(manifests) {
Expand Down Expand Up @@ -37,4 +37,4 @@ class TestContainer {
}
}

export { TestContainer };
export { TestIoCContainer };

0 comments on commit 58603e4

Please sign in to comment.