【问题标题】:Jasmine 'expect(...).withContext is not a function' errorJasmine 'expect(...).withContext is not a function' 错误
【发布时间】:2020-09-16 03:00:23
【问题描述】:

我正在寻找一种在 Jasmine 中使故障消息更具描述性的方法,并发现了此功能 https://jasmine.github.io/api/edge/matchers.html#withContext

所以我像这样在我的量角器框架中尝试它

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",

有什么想法吗?

【问题讨论】:

  • 你应该为 jasmine 覆盖或创建新函数

标签: jasmine protractor


【解决方案1】:

刚在 GitHub 上得到 Jasmine 团队的答复,说明

Protractor 使用 jasminewd 包装器,它使用 Jasmine 2.x。如果你想 要使用 Jasmine 3.x,您可以使用已发布的 Protractor 6.0 最近。在旧版本中,茉莉花的最新功能,如 withContext 函数,异步钩子(例如 onSpecDone)不可用。

除了 Protractor 版本的不同,我发现我的 grunt 任务运行器一直在使用 grunt-protractor-runner v5.0.0,它使用了 protractor 5.4.2。所以我不得不直接用量角器打开protractor.conf.js。

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 2015-06-13
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 2022-11-27
    • 2023-02-24
    相关资源
    最近更新 更多