如何为关系模型创建存根



我已经为2个模型创建了hasManyThrough关系比如:this.repository.operations(id(.create(operation(;

我可以为它创建操作和关系。但当我试图为那些有问题的方法编写测试用例时。

repository.stubs.create.resolves('test');

有人能帮我为创建一个存根吗


this.repository.operations(id).create(operation);

谢谢。

这里有一个创建存根的例子,我也使用chai进行断言。

let sandbox;
before(function () {
chai.should();
sandbox = sinon.createSandbox();

});
afterEach(function () {
sandbox.restore();
});

it('should get something', function () {
let stub = sandbox.stub(object, ‘WhatYouAreStubbing’).returns(‘something’);
let result = object.Method();
stub.calledOnce.should.be.true;
(result === undefined).should.be.false;
});

最新更新