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.

Use enzyme for specific tests in react-native

See original GitHub issue

Hello,

Currently we have basic tests with react-test-renderer as well as tests with@storybook/addon-storyshots

if I globally activate enzyme with jest:

"setupFilesAfterEnv": [
   "<Rootdir> /test/setup-enzyme.ts"
]

The snapshots of my stories will not work anymore and throw this error:

 ● Test suite failed to run

    testStorySnapshots is intended only to be used inside jest

      1 | import initStoryshots from "@storybook/addon-storyshots"
      2 | 
    > 3 | initStoryshots({
        |               ^
      4 |   configPath: "./storybook",
      5 |   framework: "react-native",
      6 | })

      at Object.testStorySnapshots [as default] (node_modules/@storybook/addon-storyshots/dist/api/index.js:37:11)
      at Object.<anonymous> (test/tests/storyshots.test.ts:3:15)

I was wondering if it was possible to activate enzyme on demand, in a beforeAll() for example.

Thanks for reply.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
loic-lopezcommented, Mar 26, 2019

Yes, i will fork and do the pull request.

1reaction
loic-lopezcommented, Mar 26, 2019

Oh! it’s working with this comment on top of the test file.

So i have created a component.enzyme.test.tsx file.

See bellow my sample:

/**
 * @jest-environment jsdom
 */
import { ModalMock } from "./ModalMock"
import * as React from "react"
import { App } from "../../../app/app"
import { mount } from "enzyme"

describe("App tested with airbnb enzyme", () => {

  beforeAll(() => {
    jest.mock("Platform", () => {
      const Platform = jest.requireActual("Platform");
      Platform.OS = "ios";

      return Platform;
    });

    jest.mock("react-native-modal", () => ModalMock);
  })


  test("App mount with enzyme", () => {
   const wrapper = mount<App>(<App/>)
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing stateful components using Enzyme
Enzyme is a JavaScript testing utility for React. You will mostly be using the shallow utility from Enzyme. Shallow utility helps us in...
Read more >
How to set up Jest and Enzyme to test React Native apps
This short article shares my experiences setting up my testing environment to unit test React Native components with Jest and Enzyme.
Read more >
Use Enzyme for testing React Native Component
This is example for use Enzyme for testing React Native Component. I have component Members.js and enter the following contents:.
Read more >
Unit testing in React Native with Jest and Enzyme - Medium
With Jest we have a very easy way to test if a component is rendered correctly given certain props and state. It's called...
Read more >
Unit Testing In React Native Applications - Smashing Magazine
Enzyme is a JavaScript testing framework for React Native applications. (If you're working with React rather than React Native, a guide is ...
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