如何解决如何为关系模型创建存根
我为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;
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。