Skip to content

Jest Config and Tricks

veeramarni edited this page Jun 14, 2019 · 5 revisions
  • Jest config file exists in the root

  • moduleNameMapper helps to map modules if a package in the test case referring to the same module.

For example, if we have

// packageB/sample.test.ts

import { something } from 'packageA';

If packageA has a packageB dependency, then jest will invoke packageB/lib/index.js. If we need to map to packageB/src/index.ts we can do using moduleNameMapper.

    moduleNameMapper: {
        '@sample-stack/server-core': '<rootDir>/packages/sample-server-core/src/index.ts'
    },

To match part of the expected object

https://stackoverflow.com/questions/49044994/how-can-i-test-part-of-object-using-jest