Skip to content

Instantly share code, notes, and snippets.

@NewGyu
Created September 11, 2014 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NewGyu/64ddef2561fdee2b63af to your computer and use it in GitHub Desktop.
Save NewGyu/64ddef2561fdee2b63af to your computer and use it in GitHub Desktop.
spyOn in gulp-jasmine
var str1 = new String();
var str2 = new String('123aa')
describe('example',function() {
it('use spy',function(){
spyOn(str1,'indexOf').andCallFake(function(s){
return 50;
});
expect(str1.indexOf('aa')).toEqual(50);
});
it('unuse spy',function(){
expect(str2.indexOf('aa')).toEqual(3);
});
});
var gulp = require('gulp');
var jasmine = require('gulp-jasmine');
gulp.task('test', function(){
gulp.src(['test/**/*Spec.js'])
.pipe(jasmine({verbose:true,includeStackTrace:true}));
});
@NewGyu
Copy link
Author

NewGyu commented Sep 11, 2014

sindresorhus/gulp-jasmine#26
このissueの報告用の再現ケースであるが、上記で自己レスしたように勘違いだった。
gulp-jasmineは内部でminijasminenode2に依存しており、これは名前が示す通りjasmine2系である。
jasmine2系からspyの書き方が変わっており、

   spyOn(str1,'indexOf').and.callFake(function(s){
    return 50;
   });

このように書くのが正しい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment