【问题标题】:Is it possible to write unit tests for select2 using jest?是否可以使用 jest 为 select2 编写单元测试?
【发布时间】:2019-07-11 21:47:05
【问题描述】:

我们有一个 Angular (7) 应用程序,我们在某些页面上使用 select2 库 (select2)。我最近将单元测试运行器从 karma 更改为 jest。包含 select2 组件的所有测试都已损坏。我试图在 setupJest.ts 上添加以下行:

global.$.fn.select2 = require('select2');

但是什么也没发生。测试抛出以下错误:

TypeError: Cannot read property 'select2' of undefined

我还没有弄清楚如何解决这个问题。

【问题讨论】:

  • 你能分享一个简单的测试来证明这个问题吗?

标签: angular unit-testing jestjs jquery-select2


【解决方案1】:

不是解决方案,但作为一种解决方法,我发现降级到 select2@4.0.3 会有所帮助。该版本通过测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-06
    • 2015-03-30
    • 2014-02-24
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    相关资源
    最近更新 更多