2017-02-26 80 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!' }); 
});