Jest : Mock import of JSON file

You can either use moduleNameMapper in your jest settings to point the import to an mocked json file.

{
  "moduleNameMapper": {
    "setting.json": "<rootDir>/__mocks__/setting.json"
  }
}

Or you can use jest.mock inside your test to mock the file directly, note that you have to add the { virtual: true } parameter.

jest.mock('path/to/setting.json', ()=>({
  settings: 'someSetting'
}), { virtual: true })

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)