Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
expect(AuthMethod(login, password));
const store = Redux.createStore(yourReducer) store.dispatch(AuthMethod(login, password)) const value = store.getState().someKey // вместо someKey нужный вам ключ
return async (dispatch) => { dispatch(AuthLoading()); try { var date = new Date().getDate(); var month = new Date().getMonth() + 1; var year = new Date().getFullYear(); var hours = new Date().getHours(); var min = new Date().getMinutes(); var sec = new Date().getSeconds(); var time = date + '-' + month + '-' + year + ' ' + hours + ':' + min + ':' + sec; let response = await fetch( 'http://' + ServerLink + ':' + ServerPort + '/tmo/rest/user', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ login: login, password: password, deviceSerialNumber: '1111111', currentAppVersion: AppVersion, currentDateTime: time, }), }, ); let data = await response.json(); if (data.sessionToken === '') { dispatch(AuthFailure('Token null')); } else { AsyncStorage.setItem('token', data.sessionToken); dispatch(AuthSuccess(data)); } } catch (e) { dispatch(AuthFailure(e.message)); } }; };`
fetchMock.getOnce('link', { body: JSON.stringify({ login: login, password: password, deviceSerialNumber: '1111111', currentAppVersion: AppVersion, currentDateTime: time, }), method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }); const AuthSuccesData = [ {type: FETCH_AUTH_LOADING}, { type: FETCH_AUTH_SUCCESS, payload: data, }, ]; expect(AuthMethod(login, password)).toEqual(AuthSuccesData);
expect(received).toEqual(expected) // deep equality Expected: data // payload из FETCH_AUTH_SUCCESS Received: [Function _callee] expect(AuthMethod(login, password)).toEqual(AuthSuccesData);
AuthMethod(login, password).then(res => { expect(res).toEqual(AuthSuccessData)) done() }