Keep all Promise implementation details internal
This commit is contained in:
+11
-13
@@ -46,21 +46,19 @@ describe("Env", function() {
|
||||
}));
|
||||
});
|
||||
|
||||
it('can configure a custom promise library', function() {
|
||||
var myLibrary = { resolve: jasmine.createSpy(), reject: jasmine.createSpy() };
|
||||
expect(env.getPromise()).toBeUndefined();
|
||||
describe('promise library', function() {
|
||||
it('can be configured with a custom library', function() {
|
||||
var myLibrary = { resolve: jasmine.createSpy(), reject: jasmine.createSpy() };
|
||||
env.configure({ Promise: myLibrary });
|
||||
});
|
||||
|
||||
env.configure({ promiseLibrary: myLibrary });
|
||||
expect(env.getPromise()).toBe(myLibrary);
|
||||
});
|
||||
it('cannot be configured with an invalid promise library', function() {
|
||||
var myLibrary = {};
|
||||
|
||||
it('fails to configure a custom promise library if library is invalid', function() {
|
||||
var myLibrary = {};
|
||||
expect(env.getPromise()).toBeUndefined();
|
||||
|
||||
expect(function() {
|
||||
env.configure({ promiseLibrary: myLibrary });
|
||||
}).toThrowError('Custom promise library missing `resolve`/`reject` functions');
|
||||
expect(function() {
|
||||
env.configure({ Promise: myLibrary });
|
||||
}).toThrowError('Custom promise library missing `resolve`/`reject` functions');
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to multiple failures for specs', function() {
|
||||
|
||||
+23
-1
@@ -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);
|
||||
|
||||
@@ -115,7 +115,8 @@ describe("SpyStrategy", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy("original"),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||
getPromise = function() { return Promise; },
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
||||
|
||||
spyStrategy.resolveValue(37);
|
||||
spyStrategy.exec().then(function (returnValue) {
|
||||
@@ -128,11 +129,9 @@ describe("SpyStrategy", function() {
|
||||
var originalFn = jasmine.createSpy("original"),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||
|
||||
spyOn(jasmineUnderTest, 'getPromise');
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.resolveValue(37);
|
||||
}).toThrowError('resolveValue requires global Promise, or a `promiseLibrary` configured with `jasmine.getEnv().configure()`');
|
||||
}).toThrowError('resolveValue requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -141,7 +140,8 @@ describe("SpyStrategy", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy("original"),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||
getPromise = function() { return Promise; },
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
||||
|
||||
spyStrategy.rejectValue(new Error('oops'));
|
||||
spyStrategy.exec().then(done.fail).catch(function (error) {
|
||||
@@ -154,11 +154,9 @@ describe("SpyStrategy", function() {
|
||||
var originalFn = jasmine.createSpy("original"),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||
|
||||
spyOn(jasmineUnderTest, 'getPromise');
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.rejectValue(new Error('oops'));
|
||||
}).toThrowError('rejectValue requires global Promise, or a `promiseLibrary` configured with `jasmine.getEnv().configure()`');
|
||||
}).toThrowError('rejectValue requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -27,19 +27,4 @@ describe('base helpers', function() {
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPromise', function() {
|
||||
it('returns a custom library if configured', function() {
|
||||
var myLibrary = { resolve: jasmine.createSpy(), reject: jasmine.createSpy() };
|
||||
jasmineUnderTest.getEnv().configure({ promiseLibrary: myLibrary });
|
||||
expect(jasmineUnderTest.getPromise()).toBe(myLibrary);
|
||||
});
|
||||
|
||||
it('returns global library if not configured', function() {
|
||||
var globalLibrary = {};
|
||||
var global = { Promise: globalLibrary };
|
||||
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
|
||||
expect(jasmineUnderTest.getPromise()).toBe(globalLibrary);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user