【问题标题】:Unit tests fail or build fail with MomentJS: undefined is not a function moment defaultMomentJS 的单元测试失败或构建失败:未定义不是默认的函数
【发布时间】:2017-06-26 14:29:51
【问题描述】:
 TypeError: undefined is not a function (evaluating 'moment_1.default()') in src/test.ts (line 74996)

拜托,拜托,拜托,看在皮特的份上,最终将 MomentJS 移植到 Angular2 和 TypeScript 并修复这个成千上万的错误吗?

或者提供一个可行的、可行的解决方案,同时适用于单元测试和生产代码。

【问题讨论】:

标签: angular unit-testing momentjs


【解决方案1】:

要在模板中使用,您可以使用ngx-moment

要使用内部服务和组件,请确保您使用的是2.13.0 或更高版本,并已按照官方documentation 中的说明使用import * as moment from 'moment'; 导入模块。

这应该可以防止 Moment 在您的单元测试中返回为 undefined

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-28
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多