score:0
Accepted answer
reference: testing with react's jest and enzyme when simulated clicks call a function that calls a promise
wrap your expect statement in setimmediate
setimmediate(() => {
expect(spotifymock.getuserinfo).tohavebeencalledtimes(1);
})
score:10
you should wrap your render-affecting calls in an async act() function as per dan abramov's blog post like so:
it('calls spotify api on click', async () => {
await act(async () => {
wrapper = mount(<user />);
});
expect(spotifymock.getuserinfo).not.tohavebeencalled();
await act(async () => {
wrapper
.find('button')
.last()
.simulate('click');
});
wrapper.update();
expect(spotifymock.getuserinfo).tohavebeencalledtimes(1);
});
Source: stackoverflow.com
Related Query
- How to test state update and component rerender after async call in react
- how and when to call a react component methods after state change from redux
- How does React update a component and its children after a state change?
- How to test api call in react component and expect the view change after success of api call?
- React functional component test file unable to update state value and call its props function
- How to update react component state from one component to another, and call any functions from any component
- How to test a function call after state receive value inside expression in React function component using Jest
- React & Jest, how to test changing state and checking for another component
- How to TEST async calls made in componentDidMount that set the state of React Component
- react component state change after ajax call but does not rerender component
- How to test React state after calling a component method that updates state - using Enzyme
- How to update React component after changing state through redux?
- How to test redux state update with react testing library and jest
- how to set react parent component state by a async function and then pass this state to child as props?
- How to call event from component after setting its state with React hooks?
- Warning: Can't perform a React state update on an unmounted component after update context and redirect to another page
- How to call method in child component only once after parent state update
- React Redux how to dispatch async actions and update state
- How to test a React component that update over time with Jest and Enzyme?
- How to test react functional component async call
- Can't get React component to update after setting state after Axios call
- update react child component's state using props received from an async api call made in the parent component
- Call custom React async hook within a component and se it's state again
- How to test async/await API calls and update React state
- How to update a child component state after an ajax call
- How to test side-effect when state hook is passed to a child component using React and jest?
- react component does not rerender after update state
- React Context API does not update state after async call
- How to test if state of a component is changed by the function using jest and Enzyme in React TDD
- How to unit test an api call and assert state change in react and enzyme?
More Query from same tag
- Material-UI 4.1.2 Styling Select SelectInput
- Calls to local host not working with ReactJS/Axios/Express
- push elements to object based on verifications
- TypeError: this.state.edit is not a function
- React Context: When Are Children Re-Rendered?
- React JS multiple filter by buttons
- material ui Tooltip distance from the anchor
- is there a way to make onClick hanlder on a bar on Nivo charts?
- What is the Best practice for Global Variable Declaration in React.js?
- How to use page query while using root-wrapper for providing Theme with Gatsby
- Django and Reactjs: complex templates
- Is there anything wrong with injecting all of my actions into components?
- Difference between decorators and mixins in react
- How to test components wrapped in an antd Form?
- react datetimepicker with meteor
- adding new lines in react jsx element array values
- How to make an array accessible under different functions in Javascript?
- add prop types to render props function
- Proper way of server-side rendering JavaScript
- Adding a new DishdetailComponent to React application to displays the details of a Specific dish
- reactJS - useEffect() empty response using Axios GET request
- I am trying to pass date object and other nested objects in query which is getting undefined in the search page
- React 404 page not working with CSSTransition
- How to use react.usememo using react and javascript?
- Reload table data when select menu item is changed
- What is the difference between using constructor vs getInitialState in React / React Native?
- Setting props and testing nested component
- Rendering a component using React Router and Redux crashing
- Link to is behaving in different manner in React
- How to update an existing value in state array without mutation?