用sinon模拟嵌套对象

时间:2016-04-29 03:21:54

标签: javascript unit-testing sinon

我有一个测试,我正在尝试测试api调用的构造。我试图模拟api,并想知道如何使用sinon访问嵌套对象。

it('should create the correct fetch method', (done) => {
    let mock = { shop: {get: (...args) => true } };
    let api = sinon.mock(mock);
    let file = sinon.spy();
    let endpoint = 'shop.get';
    let args = {optionA: 'a', optionB: 'b'};

    api.expects(endpoint).withArgs(...args); // throws error

    fetch.call(api, endpoint, file, ...args)
      .then(() => {
        api.verify();
        done();
      });
  });

我收到此类错误: TypeError: Attempted to wrap object property shop as function

0 个答案:

没有答案