question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JEST Snapshot Testing always creates a unique identifier for the ID and htmlFor

See original GitHub issue

Hi Guys

I’m using redux-form and Jest snapshot testing in our application. Unfortunately there is a problem regarding the snapshot creation. Every time the snapshot is created the ID and the htmlFor attribute on the form field changed to a different unique ID.

Am i doing something wrong, or is that a known problem?

I’m running the following test for a Login component, that consists of two redux-form fields.

`describe('Login Component', () = {
    it('renders correctly', () = {
        const props = {
            onLogin: jest.fn(),
        };

        const locale = 'de';

        const store = mockStore({
            i18n: {
                locale,
                locales,
            },
            form: {},
        });

        const tree = renderer.create(
            <Provider store={store}>
                <I18n locales={locales} locale={locale}>
                    <ThemeProvider theme={theme}>
                        <Login {...props} />
                    </ThemeProvider>
                </I18n>
            </Provider>
        ).toJSON();

        expect(tree).toMatchSnapshot();
    });
});`

<Field component={TextInputWrapper} className={this.props.theme.textInput} name="email" type="email" caption={this.props.t('E-Mail')}/>

After running the test and updating the snapshot it fails because of the following problem:

ohne_titel

There is someone on stackoverflow, which has the same problem. http://stackoverflow.com/questions/41167981/how-to-stop-redux-form-or-react-from-changing-htmlfor-and-id-when-creating-jest

Can someone provide some answers regarding this problem?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
rholligercommented, Apr 25, 2017

no @anubhavDaffodil I also did the same by providing a constant ID to each Field. I think thats a reasonable way to do it 😃

0reactions
lock[bot]commented, Jun 1, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JEST Snapshot Testing always creates a unique identifier for ...
Every time the snapshot is created the ID and the htmlFor attribute on the form field changed to a different unique ID. Am...
Read more >
Jest snapshot testing React component with randomly ...
I am trying to create jest snapshot test for a React component that generates unique id using uuid. I am trying to mock...
Read more >
Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
How to Test React Components: the Complete Guide
Jest is the environment where all your tests are actually executed. This is why you do not need to import expect and describe...
Read more >
Creating snapshots in Jest for testing React applications
In this tutorial, I will lead you through using Jest, a JavaScript testing framework, to create snapshots for testing a simple React web ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found