Skip to content

Commit

Permalink
test: test typescript usage
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchuech committed Jul 8, 2016
1 parent 8373c62 commit 0991506
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
11 changes: 11 additions & 0 deletions spec/exampleclass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import TinyDiInjectableBase from '../dist/injectable';

export default class MyClass extends TinyDiInjectableBase {
constructor(private dep: any) {
super();
}
}
MyClass.$inject = {
deps: ['dependency'],
callAs: 'class'
};
28 changes: 28 additions & 0 deletions spec/typescript.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
///<reference path="../tiny-di.d.ts" />
import TinyDiInjectableBase from '../dist/injectable';

describe('typescript class', () => {
it('can define $inject property', () => {
class MyClass extends TinyDiInjectableBase {}
MyClass.$inject = ['dependency'];
expect(MyClass.$inject).toBeDefined();
});

it('can be loaded by tiny-di', () => {
let tiny = require('../dist');
let injector: TinyDiInjector = new tiny();
injector.setResolver(resolver);
injector.bind('dependency').to('exampleDep');
injector.bind('myClassInstance').load(__dirname + '/exampleclass.js');

let instance = injector.get('myClassInstance');
expect(instance.dep).toEqual('exampleDep');
});
});

/**
* define resolver to load default exported classes
*/
function resolver(module: string) {
return require(module).default;
}
2 changes: 1 addition & 1 deletion src/injectable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class TinyDiInjectableBase {
public static $inject: string[] | {
public static $inject: string[] | {
deps: string[],
callAs: 'class' | 'function'
};
Expand Down
18 changes: 18 additions & 0 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"noImplicitAny": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"target": "es5",
"outDir": "buildspec"
},

"exclude": [
"node_modules",
"src",
"buildspec"
]
}

0 comments on commit 0991506

Please sign in to comment.