【发布时间】:2017-01-04 15:14:11
【问题描述】:
我有以下示例测试:
import { assert } from 'chai'
function starWarsMovies () {
fetch('http://swapi.co/api/films/')
.then((res) => {
return res.json()
})
.then((res) => res.count)
}
describe('Get star war movies', () => {
it('should get 7', () =>{
assert.equal(starWarsMovies(), 7)
})
})
但我得到了
ReferenceError: fetch is not defined
我必须使用什么来测试获取请求。
更新
我也试过了:
import { polyfill } from 'es6-promise'
import fetch from 'isomorphic-fetch'
然后我得到:
AssertionError: expected undefined to equal 7
我不明白为什么。
【问题讨论】:
标签: javascript testing mocha.js fetch-api chai