14

I'm using JSON schema file for form creation and validation. When I'm going to test that component, in jest testing environment all imported *.json files getting undefined.

E.g. import schema from "./schema.json" in test environment schema is undefined. Please let me know if anyone getting fixed this issue.

Thanks.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
TIJ
  • 2,771
  • 3
  • 19
  • 32
  • alternatively, have you tried using `const schema = require('./schema.json);`? – Jee Mok Jul 12 '18 at 08:40
  • https://stackoverflow.com/questions/46676238/how-to-import-json-file-on-jest-tests – BenW Jul 12 '18 at 08:47
  • oh, I forgot to try that :). Thanks, it's working now. But is there a way to use es6 `import` with jest for this case. That means any babel plugin or whatever? – TIJ Jul 12 '18 at 08:48
  • 1
    @BenW I'm using create-react-app and it already using babel-jest but still `import` not working. – TIJ Jul 12 '18 at 09:37
  • Have you tried `import * as schema from "./schema.json" ` – Baptiste F. Oct 25 '22 at 08:24

0 Answers0