0
votes

While running unit test cases i want to be able to import a json file in my typescript code. The tests folder is excluded in the tsconfig.json file

The contents of the file are quite large and adding to a .ts file takes a long to load the file.

How do i include my sampleData.json only during the unit test case execution right now i get a compile error "Cannot find module '../../sampleData.json'. Consider using '--resolveJsonModule' to import module with '.json' extension..." even though the resolveJsonModule is set to true .

I do not want the json file be a part of the build

enter image description here

1

1 Answers

0
votes

How did you import your file ?

If this is by default import, ex: import bla from './bla.json'. You have to add "esModuleInterop": true to your tsconfig.