Prevent React from warning about specific unrecognized mock properties


Is there a way have React ignore specific properties at unit test time to avoid seeing a plethora of warnings in the console?

Some of our unit tests are mocking objects, which is causing React to warn about unrecognized props:

Warning: React does not recognize the _isMockFunction prop on a DOM element.

Warning: React does not recognize the getMockImplementation prop on a DOM element.

Warning: React does not recognize the mockClear prop on a DOM element.

… and so on and so forth.

We are using the mock method of the npm package ‘jest-mock-extended’, as well as normal jest.fn() mocks.

I’ve looked into these warnings and the usual solution of "don’t pass in those properties" won’t work, here. We can’t change the code just to make tests work better, and the objects being passed in need to remain mocks. (Unless I’m wrong about that, in which case please do share better ways!)

Source: React – Stack Overflow

November 22, 2021
Category : News
Tags: jestjs | mocking | reactjs | unit testing

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.