11

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
  • 19,620
  • 7
  • 50
  • 62
TIJ
  • 2,262
  • 3
  • 17
  • 31
  • 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

0 Answers0