2017-02-26 111 views

回答

0

TL; DR:fetch-absolute正是這麼做的。

詳細:

您可以創建的fetch頂部一個抽象層。您可以簡單地使用fetch-absolute

const fetch = require('node-fetch'); 
const fetchAbsolute = require('fetch-absolute'); 

const fetchApi = fetchAbsolute(fetch)('http://localhost:3030'); 

it('should should display "It works!"', async() => { 
    const response = await fetchApi('/'); 
    const json = await response.json(); 
    expect(json).to.eql({ msg: 'It works!' }); 
});