问题: Jest27中报错 angular.mock.module is not a function
环境中使用的各个库的版本 AngularJs1.5.8; Jest27.0.6
1. AngularJs官方文档中指出:
This function is declared ONLY WHEN running tests with jasmine or mocha
查看源码发现:
使用不同版本的jest,然后在测试文件中分别打印window对象,Jest26版本window对象中有jasmine对象,而Jest27版本中打印信息中无jasmine对象
2. Jest和Jasmine到底是什么关系呢?
在Jest官网,有关jest对AngularJs框架的支持,给出的参考信息列表中,有篇博客Running AngularJs Tests with Jest中提到了二者的关系:
Jest uses a modified version of Jasmine as its test runner
最开始使用的Jest版本是21,后升级到26.6.3也是可以正常运行的, 但升级到27版本之后不可用
在Jest Recent Posts中有说明:
Jest 27 will ship with a new teste runner "jest-circus" and the Node.js environment by default.
jest-jasmine2 and jest-environment-jsdom will still be bundled so users can keep using them by changing one-line each in the configuration.
本测试用例中Jest相关配置在package.json文件中:
另外还提到了关于Jest28中有关jasmine的一些计划:
Jest 28 will remove jest-jasmine2 and jest-environment-jsdom from the default distribution of Jest. The packages will still be actively maintained as part of the Jest project and be published separately. Users will need to install these packages to use them.