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:
11
.travis.yml
11
.travis.yml
@@ -24,7 +24,16 @@ matrix:
|
|||||||
include:
|
include:
|
||||||
- env:
|
- env:
|
||||||
- USE_SAUCE=false
|
- 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:
|
- env:
|
||||||
- JASMINE_BROWSER="safari"
|
- JASMINE_BROWSER="safari"
|
||||||
- SAUCE_OS="OS X 10.11"
|
- SAUCE_OS="OS X 10.11"
|
||||||
|
|||||||
@@ -5010,7 +5010,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {Function} fn The function to invoke with the passed parameters.
|
* @param {Function} fn The function to invoke with the passed parameters.
|
||||||
*/
|
*/
|
||||||
this.callFake = function(fn) {
|
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);
|
throw new Error('Argument passed to callFake should be a function, got ' + fn);
|
||||||
}
|
}
|
||||||
plan = fn;
|
plan = fn;
|
||||||
|
|||||||
@@ -92,12 +92,35 @@ describe("SpyStrategy", function() {
|
|||||||
expect(returnValue).toEqual(67);
|
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() {
|
it('throws an error when a non-function is passed to callFake strategy', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
var originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
||||||
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
|
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
|
||||||
|
|
||||||
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
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 () {
|
expect(function () {
|
||||||
spyStrategy.callFake(function() {});
|
spyStrategy.callFake(function() {});
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {Function} fn The function to invoke with the passed parameters.
|
* @param {Function} fn The function to invoke with the passed parameters.
|
||||||
*/
|
*/
|
||||||
this.callFake = function(fn) {
|
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);
|
throw new Error('Argument passed to callFake should be a function, got ' + fn);
|
||||||
}
|
}
|
||||||
plan = fn;
|
plan = fn;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ rm -rf ~/.nvm
|
|||||||
git clone https://github.com/creationix/nvm.git ~/.nvm
|
git clone https://github.com/creationix/nvm.git ~/.nvm
|
||||||
(cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`)
|
(cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`)
|
||||||
source ~/.nvm/nvm.sh
|
source ~/.nvm/nvm.sh
|
||||||
nvm install v0.12.18
|
nvm install ${1:-"v0.12.18"}
|
||||||
|
|
||||||
npm install
|
npm install
|
||||||
npm test
|
npm test
|
||||||
|
|||||||
Reference in New Issue
Block a user