Categories
Development

jest failing with “Target container is not a DOM element.” cause it tests my index.tsx

So i want to set up testing on a react project i working on. i set up some test files, but jest always fails with Test suite failed to run Target container is not a DOM element. 4 | import App from ‘~/App’; 5 | > 6 | ReactDOM.render(<App />, document.getElementById(‘root’)); | ^ 7 | […]

Categories
Development

Jest & React & Typescript & React-Testing-Library error

I have a React/NextJS project setup using Typescript and am adding unit testing with Jest and React Testing Library. A unit test for my component looks like this: import React from ‘react’; import ‘@testing-library/jest-dom/extend-expect’; import { render } from ‘@testing-library/react’; import AppLayout from ‘.’; describe(‘<AppLayout>’, () => { it(‘renders children’, () => { const children […]

Categories
Development

“Navbar refers to a value, but is being used as a type here” when trying to render a shallow copy of my component when testing

I am trying to write a test to my React component, using TypeScript, Jest as my test runner and Enzyme for testing my React components. Whenever I pass my component into the shallow Enzyme function, I get the ts error “‘Navbar’ refers to a value, but is being used as a type here.”, and underneath […]