redux-thunk

redux-thunk structure and test side effects

馋奶兔 提交于 2019-12-11 09:29:08
问题 I am using redux-thunk and not sure if side effects ( showAlertError function) are structured properly. Although my jest test setup seems to be fine at first glance, I get an error: jest.fn() value must be a mock function or spy. Received: undefined` Is the showAlertError function is at the right place or it should be in the action creator or somewhere else? Also if this is the right place for it then how I can test if it's called. export const submitTeammateInvitation = (data) => { const

Uncaught TypeError: Providing your root Epic to createEpicMiddleware(rootEpic)

流过昼夜 提交于 2019-12-11 06:37:26
问题 I am getting this error Uncaught TypeError: Providing your root Epic to createEpicMiddleware(rootEpic) is no longer supported, instead use epicMiddleware.run(rootEpic) When simply using import 'rxjs' import { createStore, combineReducers, applyMiddleware } from 'redux' import { reducer as formReducer } from 'redux-form' import thunk from 'redux-thunk' import promise from 'redux-promise-middleware' import { createEpicMiddleware, combineEpics } from 'redux-observable' import app from './app' //

How can I check in a jest test if a thunk action within a thunk action creator has been dispatched?

℡╲_俬逩灬. 提交于 2019-12-11 05:42:30
问题 Here's a generalized example: // myActions.js export const actionOne = () => (dispatch) => { dispatch(actionTwo()); }; export const actionTwo = () => ({ type: 'SOME_TYPE', }); I would like to test that actionTwo has been either called or dispatched, ideally without the test knowing anything about what is going on in actionTwo , because I have a different test that takes care of that. I am using redux-mock-store to dispatch the tested action to a mocked store and calling store.getActions() to

How to add `redux-thunk` and `redux-promise`?

三世轮回 提交于 2019-12-11 05:09:51
问题 My boilerplate is reverse order from the redux-thunk docs. My boilerplate createStore is the argument, but the docs use createStore as a function. I am confuse now. How can I implement the store correctly? I need to use redux-thunk. But my boilerplate is like this import React, {Component} from 'react'; import './App.css'; import SelectTeam from "./components/select_teams"; import reducers from './reducers/index'; import {Provider} from 'react-redux'; import promise from "redux-promise";

How to make thunks independent from state shape to make them portable?

天涯浪子 提交于 2019-12-10 21:43:08
问题 I've developed a smallish standalone web app with React and Redux which is hosted on its own web server. We now want to reuse/integrate most parts of this app into another React/Redux web app. In theory this should work quite nicely because all my React components, reducers and most action creators are pure. But I have a few action creators which return thunks that depend on the app state. They may dispatch async or sync actions, but that's not the issue here. Let's say my root reducer looks

redux-thunk with typescript

三世轮回 提交于 2019-12-10 16:48:29
问题 I am trying to learn redux and I am trying to implement the redux-thunk middleware. I've been following a few different tutorials and they suggest something similar to this: import thunk from "redux-thunk"; import promise from "redux-promise-middleware"; ... const middleware = applyMiddleware(promise(), thunk); const store = createStore(reducers, middleware); This gives me the following error: /Users/me/Documents/workspace/redux/node_modules/redux-thunk/index.d.ts (4,47): Generic type

How can I test Action of Redux-Thunk use Unit Test Jest?

╄→гoц情女王★ 提交于 2019-12-10 16:45:21
问题 I'm new to unittesting a Action of Redux-thunk use Jest . Here is following Code : export const functionA = (a,b) => (dispatch) =>{ dispatch ({type: CONSTANT_A, payload: a}); dispatch ({type: CONSTANT_B, payload: b}); } How can i test for the function use Unit-Test Jest ? Anyone can help me ^^. Thank in advance :) 回答1: You have an example in the Redux docs: http://redux.js.org/docs/recipes/WritingTests.html#async-action-creators import configureMockStore from 'redux-mock-store' import thunk

Redux-thunk: `dispatch is not a function`

杀马特。学长 韩版系。学妹 提交于 2019-12-10 11:38:24
问题 So, I'm having an issue with an action returning the above mentioned error (See attached image), instead of updating redux state as expected. What am I overlooking here? actionCreators.js export function userToken(token) { console.log('userToken has been fired'); return (dispatch) => { dispatch({ type: 'Graphcool_Token', payload: token }); } } App.js .... // Root Query const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, { options: { cachePolicy: 'offline-critical', fetchPolicy:

Initialize component with Async data

a 夏天 提交于 2019-12-10 01:06:53
问题 I'm trying to figure out how and where to load the data (ie call dispatch on my action) for my select box in react + redux + thunk. I'm not sure if it should go in the constructor of my App container, or should i load it inside my component (in my example: "MyDropdown") My main App: import MyDropdown from '../components/mydropdown'; // Should i import my action here and then... // import { loadData } from '../actions'; class App extends Component { render() { return ( <div className="page

TypeError: middleware is not a function

吃可爱长大的小学妹 提交于 2019-12-09 14:10:55
问题 I'm trying to apply redux in my reactjs app. I can't proceed because of these errors: I'm sure that I already installed all the dependencies that I need. Here is a relevant part of my package.json "dependencies": { "react-redux": "^5.0.6", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-promise": "^0.5.3", "redux-thunk": "^2.2.0", } Here is a part of my index.js that implements redux import { createStore, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import