score:2
enzyme shallow
is primarily intended for isolated unit tests like the one that was listed, only the implementation of tested unit is asserted. it offers some instrumentation (and also non-compliant behaviour) that doesn't exist in react itself.
react-testing-library is primarily intended for blackbox functional tests, the effects of units on resulting dom are asserted.
react's own reacttestutils also offer some basic functionality, a subset of enzyme and react-testing-library features, including shallow renderer for isolated tests.
it's possible to do isolated tests and assert the implementation without enzyme, this results in boilerplate code. the approach isn't specific to testing library, it could be achieved with any renderer, including react's test renderer's snapshot testing. everything (counter
component) but tested unit (app
component) should be mocked with jest, e.g.:
it('passes all props to counter wrapper', async () => {
const countermock = jest.fn(() => 'counter');
jest.mock('./counter-module', () => countermock);
const app = await import('./app-module');
// render <app/> and assert that the result is <div>counter</div>
expect(countermock).tobecalledwith({ counter: 0 });
});
Source: stackoverflow.com
Related Query
- How do I test props passed to child component using Enzyme Shallow?
- Test if props are passed (Without using Enzyme)
- How to test onClick props of a button using Jest and Enzyme
- Using Jest and Enzyme to test functional React components that are using Redux
- How can I test custom callbacks passed to Axios API using jest + enzyme
- How do I test string that is being passed as props jest enzyme ReactJS
- How To Test functions passed as props in React, Jest, Enzyme
- Test onClick of a button is called when there is no props passed down to it using testing library react and jest
- How to test if a component is rendered with the right props when using react-testing-library?
- How do you mock useLocation() pathname using shallow test enzyme Reactjs?
- How to write test case for ErrorBoundary in React using Jest / Enzyme
- How to unit test useEffect cleanUp return function using Jest and Enzyme
- How to mock functions, and test that they're called, when passed as props in react components?
- Why are my props `undefined` when using redux and react.js?
- How to test methods inside functional component using enzyme as instance() returns null for shallow wrapper?
- Checking props of a child component with shallow rendering using enzyme
- How to test conditional rendering of components using Jest and Enzyme
- How to test default props functions is attached to component or not ? | React | Jest | Enzyme
- How can I test functions that are provided by context using jest and react-testing-library?
- React - How to access props without using constructor
- why react props are passed undefined to the child component?
- React test componentWillReceiveProps using enzyme
- How to test React state after calling a component method that updates state - using Enzyme
- How to test methods and callback using Mocha, Chai, & Enzyme in React-Redux
- React Navigation losing props that are passed down
- How to set focus on a TextField\input using a Formik form when initialValues are passed through\bound to props.object?
- Test custom method on React component has been called, using Enzyme and Sinon
- Using Jest and Enzyme, how do I test a function passed in through props?
- React Testing Library: Test if children are passed / rendered correctly
- 'match' property not set on props when using MemoryRouter in test
More Query from same tag
- React, page is refreshing constantly
- Multi-select with Select all Option in ANTD React
- Props not setting state
- Material ui class based components
- How can I import a js file that contains a self calling function onto a React component?
- Multi-nested controlled components React
- Gatsby keeps complaining Cannot query field "fields" on type "MarkdownRemark" when I have allMarkdownRemark
- Return a message for a search display zero search results in react hooks
- How can I pass a function with a index element down the component?
- Dynamic React-Router 1.0.0-rc3
- how do you make validation in redux-form based on state?
- Using context.drawImage() with a MediaStream
- React Router v4 not displaying components
- mongoDB is not working after I deployed my MERN app using Heroku, while the app works fine on my localhost
- ReactJS - How To Setup 3 Divs One On-Top Of The Other?
- docker-compose up exit with code 0 for react js
- Right way to iterate nested object
- how should I build onClick action in my react component + Redux
- How to display React-Bootstrap's NavDropdown on Hover
- How to add a permanent filter function to a List view in react-admin?
- How to call props function in axios response in react.js
- How to create Accordion using Card Component
- Is there a way in jest to check for a div by classname and then check the style?
- React-FontAwesome icon doesn't appear when favicon is set
- React - .map returning not a function?
- React onClick on stateless component
- how to fire mouse event click on tab
- GraphQL Unexpected end of JSON input
- How can I get the checkbox and label to line up in a form with React?
- React Material Theme Chooser