score:11
Accepted answer
Even if the rendering is shallow, you can call the wrapper.instance()
method.
it("should call sort ids", () => {
const wrapper = shallow(<Chat />);
wrapper.instance().sortIds = jest.fn();
wrapper.update(); // Force re-rendering
wrapper.instance().componentDidMount();
expect(wrapper.instance().sortIds).toBeCalled();
});
Source: stackoverflow.com
Related Query
- How do I test component methods on a React component that are defined as arrow functions (class properties)?
- How to test a react component that is dependent on useContext hook?
- How do react hooks determine the component that they are for?
- How to TEST async calls made in componentDidMount that set the state of React Component
- How can I write a unit test for a react component that calls reduxjs's mapStateToProps?
- How to test that Redux's dispatch() has been called in React Component (Jest + Enzyme)
- How to unit test a React component that renders after fetch has finished?
- How to test React state after calling a component method that updates state - using Enzyme
- How can I unit test parent react components that call methods on children
- React - how to stub component methods that use property initializer syntax?
- How to test a React component that has Router, Redux and two HOCs... with Jest and Enzyme?
- How to test a React component that uses context like in react-router 2.0 with Jest 0.8.x
- React testing library + Jest: How to test a component that receives a number then format it
- How do I test a React component that calls a function on its parent, which changes props on the component?
- How to properly test react component methods
- Mocha & Enzyme - How to test that React component has no children?
- How to test a React component that renders a Redux-connected component as a child without providing mock Redux store?
- How to test if styles are dynamically applied on a React component
- How to test a React component that update over time with Jest and Enzyme?
- How to use react-alert with React component that is defined as ES6 class
- How to test a React component that dispatches a Redux / Thunk action
- React Testing Library: How to test a component that requires the useState hook from its parent?
- How to test arrow function calling in react component with jest?
- How do I test component that uses react context API?
- How do I use jest to test a React component that imports a component that imports jQuery UI
- How to redirect to a url along with a component in react such that props passed to the component are not lost
- How to unit test react hooks component that fetches data in useEffect using Enzyme?
- How to test a component that isn't exported in React
- How can I test react component that fetches the data from firestore?
- How to test react image component that gets it's src attribute from a REST api
More Query from same tag
- AJAX Jquery Call returning 401 (unauthorized) - API Call
- Showing the list of array items using condition in ReactJS
- React app state not updating
- Ajax call in React Starter Kit
- Correct way to calculate download percentage with node-fetch
- React API call returns empty response then returns the data
- How to send variable value from child to parent in React without using Redux
- Loops inside react jsx render function with if else conditions
- How to pass value from parent component to child component (react)
- react cookie consent not registering on first site visit
- How to create Generic event handler with React TypeScript
- How to fix "TypeError: fsevents is not a constructor" react error
- Force React container to refresh data
- How to reset my filter options to their initial blank state? React
- CsvDownloader leaves data empty
- How to scroll to particular id component using ant-design steps
- React Hooks - set state to initial state
- Show validation feedback to the user
- AutoComplete(MUI) I am trying to set a default Value in the checkbox from an API, but getting (intermediate value).filter is not a function error
- ReactJS SocketIO setState to JSON Object
- Display HTML page response in react js
- Override a Material UI style without using an HOC?
- Adding Disabled Attribute to dynamically created Button In React
- Access container props in mapDispatchToProps
- how to select one checkbox from a mapped multiple checkboxes React.js
- Reactjs Warning: input is a void element tag and must not have `children` or use `props.dangerouslySetInnerHTML`. Check the render method of null
- Call API Every X Seconds in React Function Component
- How to add action column in ag grid having edit/delete button for each row in react?
- What is the purpose of having a didInvalidate property in the data structure of a react-redux app's state?
- React button hover css pseudoclass not working