Skip to content

How to separate tests for web and native? #1967

Pinned Answered by necolas
victorfernandesraton asked this question in Q&A
Discussion options

You must be logged in to vote

You can use jest projects to configure different test environments, and match against different file extensions for platform-specific tests. Configure jest to produce platform-specific snapshots too. Then when you run jest it can correctly run any combination of web-only, native-only, and multiplatform unit tests.

For example:

// jest.config.js

module.exports = {
  projects: [
    {
      displayName: 'web',
      moduleNameMapper: {
        // alias react-native
        '^react-native$': 'react-native-web'
      },
      // store DOM snapshots
      snapshotResolver: '<rootDir>/configs/jest-web-resolver.js',
      // use jsdom
      testEnvironment: 'jsdom',
      testMatch: [
        /…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by necolas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants