0.1.0 • Published 10 years ago
blog-it-stub v0.1.0
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 itthenResolveWith(resolvedValue)
: tells the stub it should resolve with resolvedValuethenRejectWith(rejectValue)
: tells the stub it should reject the promise with rejectValueflush()
: effectively resolve/reject the stub (note it is anasynchronous operation
therefore you should put your assertion in the callback of the promisehasBeenResolved()
: tells whether the stub has been resolvedhasBeenRejected()
: tells whether the stub has been rejected
Test
run npm test
License
MIT
0.1.0
10 years ago