angular2-testing-micro
v1.3.0
Published
Jasmine-free Angular 2 Testing Library
Downloads
10
Readme
angular2-testing-micro
Jasmine-free Angular 2 Testing Library
Why micro?
angular2/testing
depends on Jasmine and wraps it for DI.
I need Jasmine-free testing library for Angular2 because I want ...
- Simple API
- Less code
- Custom assertion (I ♥ power-assert)
Install
$ npm install --save-dev angular2-testing-micro
Usage (Mocha & power-assert example)
Model
Simple mocha test
import assert = require("power-assert");
describe("TestModel", () => {
it("can instantiate", () => {
let model = new TestModel("AAA");
assert(!!model);
});
describe("toString()", () => {
it("should return string", () => {
const model = new TestModel("AAA");
const str = model.toString();
assert(typeof str === "string");
});
});
});
Service
Inject Http
describe("TestService", () => {
beforeEach(() => {
resetBaseTestProviders();
getTestInjector().addProviders([
BaseRequestOptions,
MockBackend,
provide(Http, {
useFactory: (backend: MockBackend, options: BaseRequestOptions) => {
return new Http(backend, options);
}, deps: [MockBackend, BaseRequestOptions]
}),
TestService
]);
});
it("can instantiate", inject([TestService], (service: TestService) => {
assert(!!service);
}));
});
Component
Ported TestComponentBuilder
describe("TestAppComponent", () => {
beforeEach(() => {
resetBaseTestProviders();
setupTestBrowserProviders();
});
it("can create", inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TestAppComponent, [
provide(TestService, {
useValue: {
get: (id: string) => {
return Observable.empty();
}
},
}),
])
.then(fixture => {
assert(!!fixture);
});
}));
});
License
MIT