1.3.0 • Published 8 years ago

angular2-testing-micro v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

angular2-testing-micro

Circle CI npm version

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 ...

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

1.3.0

8 years ago

1.2.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago