我有一個簡單的測試,我想測試一個服務,它是前端的方法。在後端我使用require()
來獲取模塊,但前端使用webpack和import
。使用`import`語句而不是`require`調用單個摩卡測試
我的測試:
const testee = require('../network-template.service');
describe('getTemplates', function() {
it('shall return templates from server', function (done) {
console.log(testee);
done();
});
});
我的測試類:
import fetch from 'isomorphic-fetch';
const ENDPOINT = 'http://localhost:3000/api/network-templates';
class NetworkTemplateService {
getTemplates(){
return fetch(ENDPOINT, {
method: 'GET',
headers: {
'Accept' : 'application/json'
},
body: JSON.stringify(ports)
})
.then(response => ({response}))
.catch(error => ({error}));
}
有一個簡單,快捷的方式如何運行這個測試?我喜歡在後端如何編譯,無需任何設置即可立即運行所有測試。
如果你想使用進口和在前端,我認爲你必須測試你的組件預編譯,所以你可以測試一下。 –