问题描述
我为2个模型创建了hasManyThrough关系 像这样:this.repository.operations(id).create(operation);
我能够为其创建操作和关系。但是,当我尝试为有问题的方法编写测试用例时。
func application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDevicetoken devicetoken: Data) {
// ...and access appState here
AppState.shared.user = ...
}
谁能帮我为它创建一个存根
repository.stubs.create.resolves('test');
谢谢。
解决方法
这里是创建存根的示例,我也使用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;
});