Ich habe folgendes Beispiel Test:Prüfung holt mit Mokka und chia
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)
})
})
Aber ich
ReferenceError: fetch is not defined
bekommen, was ich verwenden, um eine Anfrage holen zu testen.
UPDATE
ich auch versucht:
import { polyfill } from 'es6-promise'
import fetch from 'isomorphic-fetch'
aber dann bekomme ich:
AssertionError: expected undefined to equal 7
und ich verstehe nicht, warum.
Versuchen Sie dies https://mochajs.org/#asynchronous-code? –