XMLHttpRequest is not defined when testing react-native app with jest -
i trying test apiwrapper in react-native based app using jest (integration testing). when run in ios simulator runs fine wont run jest tests correctly - get:
referenceerror: xmlhttprequest not defined
when try run tests using api wrapper, eg.:
it('login successful correct data', () => { let api = api.getinstance(); return api.login("test", "testpass") .then(result => expect(result).toequal('login_successful')); });
the api class trying test here use fetch api (not vanilla xhr). assume related jest trying mock have not found way make work yet.
thanks in advance.
i had similar problem lokka
using xmlhttprequest
. made mock lokka
, api wrapper class depends on. try mocking api wrapper.
this lokka
mock looks now. i'll add more when start testing error handling.
export default class { query() { return new promise(resolve => { resolve(200); }); } }
you might able mock api wrapper similar:
export default class api { getinstance() { \\ implemented getinstance } login(user, password) { return new promise(resolve => { resolve('login_successful'); }); } }
Comments
Post a Comment