Guest User

Untitled

a guest
Sep 17th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ACTION CREATOR redux-promise jako middleware
  2.  
  3. export function fetchRecipes(ingridients) {
  4.     const url = `${ROOT_URL}?i=${ingridients}`
  5.     const request = axios.get(url)
  6.     return {
  7.         type: FETCH_RECIPES,
  8.         payload: request
  9.     }
  10. }
  11.  
  12. // Test
  13.  
  14. describe('async actions', ()=>{
  15.  
  16.     const middlewares = [promiseMiddleware];
  17.     const mockStore = configureMockStore(middlewares)
  18.  
  19.     it('dispatches FETCH_RECIPES', (done)=>{
  20.  
  21.         const initialState = {
  22.             recipes: []
  23.         }
  24.         const store = mockStore(initialState)
  25.         const expectedAction = {"type":"FETCH_RECIPES","payload":{}}
  26.    
  27.         return store.dispatch(actions.fetchRecipes()).then(()=>{
  28.                 expect(actions.fetchRecipes()).toEqual(expectedAction)
  29.             })
  30.  
  31.     })
  32. })
  33.  
  34. // error z consoli
  35.  
  36. ● async actions › dispatches FETCH_RECIPES
  37.  
  38.     expect(received).toEqual(expected)
  39.  
  40.     Expected value to equal:
  41.       {"payload": {}, "type": "FETCH_RECIPES"}
  42.     Received:
  43.       {"payload": {}, "type": "FETCH_RECIPES"}
  44.  
  45.     Difference:
  46.  
  47.     - Expected
  48.     + Received
  49.  
  50.       Object {
  51.     -   "payload": Object {},
  52.     +   "payload": Promise {},
  53.         "type": "FETCH_RECIPES",
  54.       }
Advertisement
Add Comment
Please, Sign In to add comment