I am wanting to utilise the react-remove-properties babel plugin, however after introducing it, it seems to make my tests fail...
My simplified component
<div data-testid="my-tag">Hello world</div>
My simplified test
const provider = <Provider store={mockStore(store)}><MyComponent /></Provider>;
const {queryByTestId} = render(provider)
it('should display tag text', () => {
expect(queryByTestId('my-tag').textContent).toBe('Hello world');
});
Before adding the babel plugin, this test passed!
After adding the plugin to remove the data-testid
tags, the test is failing with:
TypeError: Cannot read property 'textContent' of null
32 | const {queryByTestId} = render(provider);
33 |
> 34 | expect(queryByTestId('my-tag').textContent).toBe('Hello world');
| ^
35 |
36 | });
It seems that the babel plugin is running before my test and removing the data-testid
tags first, so they cannot be found during testing.
Can anybody offer any advice on how to rectify this?
Aucun commentaire:
Enregistrer un commentaire