我是Jasmine
的新手,我想知道我們是否可以爲同一個方法創建2個間諜。這是我正在嘗試的。茉莉花 - 兩個間諜的方法相同
describe('something', function() {
beforeEach(function() {
mySpy = jasmine.createSpyObj('mySpy', 'functionInInterest');
mySpy.functionInInterest.andCallFake(function (cb) {cb(something);});
}
//Some Test Cases
describe('Here is the action!', function() {
mySpy = jasmine.createSpyObj('mySpy', 'functionInInterest');
mySpy.functionInInterest.andCallFake(function (cb) {cb(somethingElse);});
//Some test cases that depends on somethingElse
});
});
測試用例Here is the action!
取決於mySpy.functionInInterest.andCallFake(function (cb) {cb(something);});
其中作爲測試用例之前內部Here is the action!
取決於mySpy.functionInInterest.andCallFake(function (cb) {cb(somethingElse);});
注:兩個具有相同的名稱
我怎樣才能做到這一點?提前致謝!
是的,你可以做到這一點,但也許你的問題是,你要重寫mySpy? –
雅有點。間諜在beforeEach被稱爲相當在我的描述/它 – Abilash