2017-09-14 29 views
1

我有一個類的構造函數,具有功能我想存根:嘲諷命名爲進口和構造器ES6和艾娃

class Service { 
    constructor(){} 
    async someFunction() { 
    try { 
    // does stuff 
    } 
    catch (e) {} 
    } 
} 

在我要測試的文件,這是進口的,像這樣的使用:

const { Service } = require('something') 
const newService = new Service('xyz') 

我很努力地得到這個在我的測試中正確導入&存根。

目前正在導入這樣的:

t.context.service = { 
    Service: class Service { 
    constructor() { 
     this.someFunction = sinon.stub() 
    } 
    } 
} 

這似乎是進口的工作,但我無法通過構建版本得到一個參考回去吧。對此有幫助嗎?

我希望能夠做一個斷言,如:

t.true(t.context.service.Service.someFunction.calledOnce) 

回答