我是新手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);});
注:两者同名
我怎样才能做到这一点?提前致谢!