The relay is modern: how to simulate a relay for unit testing

I am trying to test a modern reactive container, but I have this problem.

TypeError: Cannot read property 'environment' of undefined

Here is the test code:

test('render component', () => {
  const tree = renderer.create(
    <User />,
  ).toJSON();

  expect(tree).toMatchSnapshot();
});
+6
source share
1 answer

In fact, you do not need to falsify the environment variable. I usually add:

export class User

to the class description class of the class I want to check. (Be sure to keep the default value for your connected version of the same class).

Then I can test the component in the preferred way by importing the component without the need for such a relay in my test:

 import { User } from '../User'

This eliminates the need for a ridiculous relay, and you can easily pass it to a component.

0
source

All Articles