问题
I'm new to Jasmine
and I wanted to know if we can create 2 spies for the same method. Here is what I'm trying.
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
});
});
Testcases before Here is the action!
depend on mySpy.functionInInterest.andCallFake(function (cb) {cb(something);});
where as test cases inside Here is the action!
depend on mySpy.functionInInterest.andCallFake(function (cb) {cb(somethingElse);});
Note: Both have the same name
How can I achieve this? Thanks in advance!
回答1:
instead of
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
});
do this
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
});
来源:https://stackoverflow.com/questions/18437035/jasmine-two-spies-for-the-same-method