【问题标题】:How to create a stub for relation models如何为关系模型创建存根
【发布时间】:2020-08-31 15:40:53
【问题描述】:

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

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

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

谁能帮我创建一个存根


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

谢谢。

【问题讨论】:

    标签: node.js mocha.js sinon loopback loopback4


    【解决方案1】:

    这是一个创建存根的示例,我也在使用 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;
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-25
      • 2019-02-09
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      相关资源
      最近更新 更多