Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 茉莉花-两个间谍用同样的方法_Javascript_Jquery_Jasmine - Fatal编程技术网

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