【问题标题】:PrimeNg Multiselect is failing unit testPrimeNg 多选未通过单元测试
【发布时间】:2017-10-26 22:34:35
【问题描述】:

我正在运行单元测试用例,对于包含许多primeng组件的组件,单元测试用例正在通过除多选之外的大多数组件,它给出以下错误:

undefined is not a constructor (evaluating 'this.documentClickListener()') in D:/mdp-internaltools-app/src/index.spec.ts (line 126499)
    ngOnDestroy@D:/mdp-internaltools-app/src/index.spec.ts:126499:35 <- webpack:///~/primeng/components/multiselect/multiselect.js:232:0
    ngOnDestroy
    destroyInternal

有没有人也遇到过primeng的多选组件的问题?

【问题讨论】:

  • 我经常使用任何库,这通常是因为我没有模拟组件/服务。尝试模拟它,看看它是否适合你。
  • @trichetriche 能否提供代码,如何模拟它
  • 不,我不能,因为这取决于你如何使用它。转至this page 了解更多信息
  • @trichetriche 有没有办法覆盖第三方组件的生命周期方法
  • 是的,通过模拟它。我曾经不得不模拟 12 个函数才能使我的测试工作。

标签: angular typescript jasmine karma-jasmine primeng


【解决方案1】:

这对我有用。我发现您必须在 TestBed 配置中导入 MultiSelectModule。组件模板中使用的所有primeng控件都必须在导入部分导入以防止错误。

【讨论】:

    猜你喜欢
    • 2014-03-02
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 2021-05-18
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多