0

我是新手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);});

注:两者同名

我怎样才能做到这一点?提前致谢!

4

1 回答 1

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
    });
于 2013-08-26T05:17:14.107 回答