I have a mock api setup with node/express
http://localhost:8080/api/lyric/
I'm using redux-observable to fetch the json:
const fetchLyricEpic = action$ =>
action$.ofType(FETCH_LYRIC)
.mergeMap(action =>
ajax.getJSON('/api/lyric')
.map(response => fetchLyricSuccess(response))
.catch(error => Observable.of(fetchLyricFail(error)))
)
The problem is, when I test, I am getting an api error instead of 200 using nock
:
beforeEach(() => {
nock.disableNetConnect()
nock.enableNetConnect('127.0.0.1')
})
afterEach(() => {
nock.cleanAll()
nock.enableNetConnect()
epicMiddleware.replaceEpic(rootEpic)
})
test('it creates FETCH_SUCCESS when fetching the lyric has been done', () => {
const payload = {
status: 200,
response: {
'lyric': "Lyric"
}
}
nock('http://localhost:8080')
.get('/api/lyric')
.reply(200, payload, {'Content-Type': 'application/json'})
I'm trying to follow what I read in the nock docs and also in the issues list, however, my nock api call keeps failing.
Aucun commentaire:
Enregistrer un commentaire