Javascript 茉莉花-两个间谍用同样的方法
我是《茉莉花》的新手,我想知道我们是否可以用同样的方法创建两个间谍。这就是我正在尝试的Javascript 茉莉花-两个间谍用同样的方法,javascript,jquery,jasmine,Javascript,Jquery,Jasmine,我是《茉莉花》的新手,我想知道我们是否可以用同样的方法创建两个间谍。这就是我正在尝试的 describe('something', function () { beforeEach(function () { mySpy = jasmine.createSpyObj('mySpy', 'functionInInterest'); mySpy.functionInInterest.andCallFake(function (cb) {cb(something
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这里是操作代码>依赖于mySpy.functionInInterest.andCallFake(函数(cb){cb(某物);})代码>其中作为测试用例在这里是操作代码>依赖于mySpy.functionInInterest.andCallFake(函数(cb){cb(somethingElse);})代码>
注意:两者名称相同
我怎样才能做到这一点?提前谢谢 而不是
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
});
是的,你可以这样做,但也许你的问题是你正在覆盖mySpy?是的。以前的间谍被称为“间谍”,而不是“我的描述/iTunes”中的“间谍”。幸运的是,我不能更改名称,因为这是一项有角度的服务!我知道这已经死了,但是@Abilash,您希望使用这种方法,并在创建了新的spy对象之后,构造您的控制器、服务或指令。创建spy对象后,您应该创建一个函数createController()
,它将使用在description