Nuclear Package Magnet

    blog-it-stub

    0.1.0 • Public • Published

    blog-it-stub

    simple stub library used by blog-it tests

    how to

    describe('stubbing library', function () {
     
        it('should stub resolving promise', function (done) {
     
            var original = {
                test: function () {
     
                }
            };
     
            //stub the service which should return promise
            var object = stub.when(original, 'test').thenResolveWith('value');
            var result;
     
            original.test().then(function (val) {
                result = val;
                expect(result).toEqual('value');
                expect(object.hasBeenResolved()).toBe(true);
                expect(object.hasBeenRejected()).toBe(false);
                done();
            });
     
            expect(object.hasBeenResolved()).toBe(false);
            expect(object.hasBeenRejected()).toBe(false);
            expect(result).not.toBeDefined();
     
            //flush pending promise
            object.flush();
        });
    );

    API

    • when(service, methodName): create a stub and return it
    • thenResolveWith(resolvedValue): tells the stub it should resolve with resolvedValue
    • thenRejectWith(rejectValue): tells the stub it should reject the promise with rejectValue
    • flush(): effectively resolve/reject the stub (note it is an asynchronous operation therefore you should put your assertion in the callback of the promise
    • hasBeenResolved(): tells whether the stub has been resolved
    • hasBeenRejected(): tells whether the stub has been rejected

    Test

    run npm test

    License

    MIT

    Install

    npm i blog-it-stub

    DownloadsWeekly Downloads

    3

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • lorenzofox3