changed tests to work in environments that dont support async/await
This commit is contained in:
@@ -92,23 +92,22 @@ describe("SpyStrategy", function() {
|
|||||||
expect(returnValue).toEqual(67);
|
expect(returnValue).toEqual(67);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows a fake async function to be called instead", async function(done) {
|
it("allows a fake async function to be called instead", function(done) {
|
||||||
try {
|
jasmine.getEnv().requireAsyncAwait();
|
||||||
var originalFn = jasmine.createSpy("original"),
|
var originalFn = jasmine.createSpy("original"),
|
||||||
fakeFn = jasmine.createSpy("fake").and.callFake(async function () { return 67; }),
|
fakeFn = jasmine.createSpy("fake").and.callFake(eval("async () => { return 67; }")),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
||||||
returnValue;
|
returnValue;
|
||||||
|
|
||||||
spyStrategy.callFake(fakeFn);
|
|
||||||
returnValue = await spyStrategy.exec();
|
|
||||||
|
|
||||||
|
spyStrategy.callFake(fakeFn);
|
||||||
|
spyStrategy.exec().then(function (returnValue) {
|
||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
|
expect(fakeFn).toHaveBeenCalled();
|
||||||
expect(returnValue).toEqual(67);
|
expect(returnValue).toEqual(67);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
} catch (err) {
|
}).catch(function (err) {
|
||||||
done.fail(err);
|
done.fail(err);
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error when a non-function is passed to callFake strategy', function() {
|
it('throws an error when a non-function is passed to callFake strategy', function() {
|
||||||
@@ -124,7 +123,7 @@ describe("SpyStrategy", function() {
|
|||||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||||
|
|
||||||
expect(function () {
|
expect(function () {
|
||||||
spyStrategy.callFake(async function() {});
|
spyStrategy.callFake(function() {});
|
||||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user