Jasmine 'expect(...).withContext is not a function' 错误

标签 jasmine protractor

我一直在寻找一种在 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/

相关文章:

angular - 引用错误: describe is not defined Karma jasmine angular2

javascript - 如何从 Jasmine 测试用例中解析 Angular lang json 文件( Angular 本地化模块)

javascript - 使用 RxJS 5 debounceTime 进行 AngularJS 测试

node.js - Jasmine 测试 Node.js 异步模块

javascript - 如何使用 Protractor 从浏览器向 WebDriver 发送消息?

javascript - Protractor - 框架中的错误处理

javascript - 如何测试从 Promise 对象获取数据的 Controller

angularjs - 使用 Protractor 测试 AngularJS 应用程序时出现 btstrpd 错误

javascript - 如何使用 Protractor 从非 Angular 页面导航回另一个 Angular 页面

internet-explorer - 在多个版本的 IE 中运行 Protractor e2e 测试