我是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);});
注意:两者名称相同
我怎样才能做到这一点?提前谢谢!
答案 0 :(得分:1)
而不是
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
});
这样做
describe('Here is the action!', function () {
mySpy_2 = jasmine.createSpyObj('mySpy', 'functionInInterest');
mySpy_2.functionInInterest.andCallFake(function (cb) {cb(somethingElse);});
//Some test cases that depends on somethingElse
});