Merge branch 'feature/allow-callfake-to-be-async' of https://github.com/mrlannigan/jasmine into merge-test

- Merges #1448 from @mrlannigan
This commit is contained in:
Steve Gravrock
2017-11-10 10:01:45 -08:00
5 changed files with 36 additions and 4 deletions

View File

@@ -24,7 +24,16 @@ matrix:
include:
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh"
- TEST_COMMAND="bash travis-node-script.sh v0.12.18"
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh v4"
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh v8"
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh v9"
- env:
- JASMINE_BROWSER="safari"
- SAUCE_OS="OS X 10.11"

View File

@@ -5010,7 +5010,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {Function} fn The function to invoke with the passed parameters.
*/
this.callFake = function(fn) {
if(!j$.isFunction_(fn)) {
if(!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) {
throw new Error('Argument passed to callFake should be a function, got ' + fn);
}
plan = fn;

View File

@@ -92,12 +92,35 @@ describe("SpyStrategy", function() {
expect(returnValue).toEqual(67);
});
it("allows a fake async function to be called instead", function(done) {
jasmine.getEnv().requireAsyncAwait();
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.callFake(eval("async () => { return 67; }")),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.callFake(fakeFn);
spyStrategy.exec().then(function (returnValue) {
expect(originalFn).not.toHaveBeenCalled();
expect(fakeFn).toHaveBeenCalled();
expect(returnValue).toEqual(67);
done();
}).catch(function (err) {
done.fail(err);
})
});
it('throws an error when a non-function is passed to callFake strategy', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
spyOn(jasmineUnderTest, 'isAsyncFunction_').and.returnValue(false);
expect(function () {
spyStrategy.callFake(function() {});
}).toThrowError(/^Argument passed to callFake should be a function, got/);
expect(function () {
spyStrategy.callFake(function() {});

View File

@@ -88,7 +88,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {Function} fn The function to invoke with the passed parameters.
*/
this.callFake = function(fn) {
if(!j$.isFunction_(fn)) {
if(!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) {
throw new Error('Argument passed to callFake should be a function, got ' + fn);
}
plan = fn;

View File

@@ -4,7 +4,7 @@ rm -rf ~/.nvm
git clone https://github.com/creationix/nvm.git ~/.nvm
(cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`)
source ~/.nvm/nvm.sh
nvm install v0.12.18
nvm install ${1:-"v0.12.18"}
npm install
npm test