Answer the question
In order to leave comments, you need to log in
How to write test (jest) correctly?
Hello everyone, please tell me where the error can be:
There is a tested component:
const ContractCreate = ({ isFinished, statusLevel, isError }) => {
return (
<section data-test="component-contract-create">
import React from 'react'
import { Provider } from 'react-redux'
import Enzyme, { shallow } from 'enzyme'
import EnzymeAdapter from 'enzyme-adapter-react-16'
import store from '../__data__/store'
import ContractCreate from './contract-create'
Enzyme.configure({ adapter: new EnzymeAdapter() })
export const findByTestAttr = (wrapper, val) => {
return wrapper.find(`[data-test="${val}"]`)
}
test('renders without error', () => {
const wrapper = shallow(
<Provider store={store}>
<ContractCreate />
</Provider>
)
const component = findByTestAttr(wrapper, 'component-contract-create')
console.log('component', component.length) // 0
expect(component.length)
.toBe(1)
})
Answer the question
In order to leave comments, you need to log in
Do this after creating the wrapper constant
. You will see exactly what is rendered in your wrapper. And when you see it, the problem will be easier to solve. And use a better mock store. That is, you create an object with the necessary data of your store and pass it with the store prop to the Provider
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question