please can anyone help me. When I run npm test to see every time I am getting this error. For example:
Test Activity › Renders without crashing
TypeError: Cannot read property 'find' of undefined
28 |
29 | test('Renders without crashing', () => {
> 30 | expect(wrapper.find('div')).toExist();
| ^
31 | });
32 |
33 | // test('should render one timezone <p>', () => {
at Object.<anonymous>
(src/components/Activities/Activity/Activity.test.tsx:30:20)
In my project enzyme has been used for it. I am having confused to understand why all test cases saying that find was undefined. Here I am trying to create testcases for div and p html tags.
This is my test cases app.test.tsx which is given below:
import React from 'react';
import Enzyme, { shallow, ShallowWrapper } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { App } from './index';
import { users, rooms, customers } from '../tests/mockStore';
Enzyme.configure({ adapter: new Adapter() });
describe('Test Activity', () => {
let wrapper: ShallowWrapper;
const props = {
t: jest.fn(),
users,
rooms,
customers,
id: '2343264scd',
room: 22222,
user: 10101033,
hotelierId: 1000063,
mainSource: 'admin',
col: true,
};
beforeEach(() => {
wrapper = shallow(<App { ...props } />);
});
test('Renders without crashing', () => {
expect(wrapper.find('div')).toExist();
});
test('should render one timezone', () => {
expect(wrapper.find('p').exists()).toBe(true);
});
test('should render one timezone', () => {
const text = wrapper.find('p').text();
expect(text).toEqual('09:50');
expect(wrapper.find('p').exists()).toBe(true)
});
Here my test cases were failing in index.tsx file.
import React from 'react';
import * as luxon from 'luxon';
const TimezoneIncludesDate = luxon.DateTime.fromISO(timestamp, { zone: 'America/New York' });
return (
<HotelierTimezone>
<div>
<p>{TimezoneIncludesDate.toFormat('HH:mm')}</p>
<p>{TimezoneIncludesDate.toFormat('DD MMM YYYY z')}</p>
</div>
</HotelierTimezone>
)
I am a bit confused I have doubt that is my test cases creation are wrong? It would be great help for me.