Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

javascript - Ajv not defined in Jest test

I want to test my class with jest. This class is importing ajv.js 6.12.2 and the test fails on that. So what i basicly did is:

  1. Add export default Ajv statement to the end of the ajv.js
  2. Import ajv.js with import Ajv from './lib/ajv.js'
  3. Add "transform": {"^.+\.jsx?$": "babel-jest"} to package.json
  4. Created babel.json and insert { "presets": ["@babel/preset-env"], "plugins": ["@babel/plugin-proposal-class-properties"] }

When I run the test with npm test I get the following error:

ReferenceError: Ajv is not defined

    > 4 | export default Ajv;`

When I run the script in browser Ajv could be used normally. Can anybody give me a hint what to do?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...