我一直在寻找一种在 Jasmine 中使失败消息更具描述性的方法,并发现了此功能 https://jasmine.github.io/api/edge/matchers.html#withContext
所以我在我的 Protractor 框架中尝试这样expect(true).withContext("something else").toBe(false);
运行测试并得到错误 - Failed: expect(...).withContext is not a function
这个特性是从 Jasmine 3.3.0 开始实现的,所以我检查了我的 package.json 并看到了 "jasmine": "^3.3.1"
,并且 package-lock.json 有
"jasmine-core": {
"version": "3.3.0",
任何想法有什么问题?
最佳答案
刚刚从 GitHub 上的 Jasmine 团队得到了一个回答,说明
Protractor uses jasminewd wrapper which uses Jasmine 2.x. If you want to use Jasmine 3.x, you can use Protractor 6.0, that has been released recently. In older versions the newest features of Jasmine, like withContext function, async hooks (e.g. onSpecDone) are not available.
除了 Protractor 版本的不同之外,我发现我的 grunt 任务运行器一直在使用 grunt-protractor-runner v5.0.0,它使用了 Protractor 5.4.2。所以我不得不直接用 Protractor 打开 protractor.conf.js。
关于 Jasmine 'expect(...).withContext is not a function' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55502100/