Keep all Promise implementation details internal

This commit is contained in:
Elliot Nelson
2019-05-08 09:07:01 -04:00
parent 95e1890e64
commit 4731b4ee4d
9 changed files with 107 additions and 102 deletions
+23 -1
View File
@@ -171,7 +171,29 @@ describe('Spies', function () {
expect(spy('foo')).toEqual(17);
});
describe("When withArgs is used without a base strategy", function() {
describe('any promise-based strategy', function() {
it('works with global Promise library when available', function(done) {
jasmine.getEnv().requirePromises();
var spy = env.createSpy('foo').and.resolveValue(42);
spy().then(function(result) {
expect(result).toEqual(42);
done();
}).catch(done.fail);
});
it('works with a custom Promise library', function() {
var customPromise = { resolve: jasmine.createSpy(), reject: jasmine.createSpy() };
customPromise.resolve.and.returnValue('resolved');
env.configure({ Promise: customPromise });
var spy = env.createSpy('foo').and.resolveValue(42);
expect(spy()).toEqual('resolved');
expect(customPromise.resolve).toHaveBeenCalledWith(42);
});
});
describe("when withArgs is used without a base strategy", function() {
it("uses the matching strategy", function() {
var spy = env.createSpy('foo');
spy.withArgs('baz').and.returnValue(-1);