I've not run the code in question but the line:
var topbar = TestUtils.scryRenderedComponentsWithType(page, 'TopBar');
looks suspect to me. The docs seem to suggest that you should pass a
componentClass rather than a string.
I don't see how it could possibly use the string to identify the component type. It could potentially use the
displayName to identify it by string, but I doubt it would do that.
I reckon you probably want this:
var TopBar = require('../../src/js/pages/DesignerPage'); var topbar = TestUtils.scryRenderedComponentsWithType(page, TopBar);
I have come across a similar situation where I needed to check if the child component was being rendered or not. As far as I understand jest mocks all required modules except for the one's where you specify not to. So in your case the child component Topbar will be mocked which leads me to guess that the rendered DOM won't be as expected.
As for checking if the child component was rendered I would do
which basically checks if the mocked child component was invoked or not.
If you really want to test TopBar component's output at this level you probably would want to set
as well to tell jest to not mock the TopBar component, so that the rendered DOM includes the output from TopBar component as well.
I have created a repo based on your example at Github that test for child components. There are two test files one tests for child components that are mocked and the other one doesn't mock the child component.
- How to test whether a React Component contains another component with jest?
- How to test if a React component contains another component with Tape and Enzyme?
- How to test the state of a functional component in React with Jest (No Enzyme)
- How to test with jest and typescript with types a basic react function component
- 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
- How to check the value of a nested React component in a unit test with Enzyme and Jest
- How to test styles and media queries rendered by a React component with Jest and/or Enzyme
- How to test a React component that update over time with Jest and Enzyme?
- Jest with React - How do you render an entire component and test it?
- How to make pass a test case which use enzyme shallow with contains when a React component has an event handler
- How to test a react component renders a list with jest
- How to test React component with children using jest and enzyme?
- How to test a React component having async functions with jest & enzyme
- Testing React components with Jest & Enzyme: where to test whether component props were given
- how to test component while passing boolean value with react testing library and jest
- How can i test with jest a react component who use context api?
- How to test a className with the Jest and React testing library
- How to mock React component methods with jest and enzyme
- How to test style for a React component attribute with Enzyme
- React & Jest, how to test changing state and checking for another component
- Test a React Component function with Jest
- How to test a React component with RouteComponentProps?
- How to mock out sub-components when unit testing a React component with Jest
- How to unit test a react event handler that contains history.push using Jest and Enzyme?
- How to test decorated React component with shallow rendering
- How to test a component with a nested container with React and Redux?
- How do you mock a react component with Jest that has props?
- How to test whether component contains string?
- How to test form submission in React with Jest and Enzyme? Cannot read property 'preventDefault' of undefined
More Query from same tag
- Service worker in Gatsby (react.js)
- Hash Router back button with React Router v4
- Refreshing a browser's cache while developing with gulp
- Context API loses data on switching router links
- Can I dynamically populate my SPFx web part's property field with all choices from a choice field
- React Error (TypeError): Can't add property context, object is not extensible
- Nav.Link to="/About" is not working in react-bootstrap? Nav.Link href="/About is working reloading the whole page
- npm start error with create-react-app with an Error Called -ELIFECYCLE
- Why nextProps & this.props happen to be same always?
- How to make input field editable on toggle with redux based on toggle?
- How can I manage multiple setState calls in the same React component?
- How to prevent redux-saga from calling my api call twice?
- Is there a way to make react-select have collapsible groups?
- resizing and fitting an image to a parent div in react
- How to update single value inside specific array item in redux
- Positioning the Element with respect to another Element in CSS
- Using a Custom Title Bar in an Electron JS App
- Cannot read property 'ensureClientConfigured' of null in Firebase Firestore - ReactJS
- Conceptually, how would I approach creating this image in react (text alignment)
- Restart Formik form after submitting from parent
- React-Bootstrap Full screen Modal Dialog
- Connect textarea with a POST request in React?
- Array of strings getting converted to Objects
- How to vertically center input field
- Module parse failed: Unexpected token (7:5) You may need an appropriate loader to handle this file type
- How to test an onChange input event with enzyme and jest
- Change component state in loop
- how to toggle class on scroll event in react?
- Trying (and failing) to write if/else expression in JSX
- Validation illegal characters in form