【问题标题】:Angular2 Material2 Karma JasmineAngular2 Material2 Karma Jasmine
【发布时间】:2016-04-27 15:58:55
【问题描述】:

我正在尝试使用 Karma 和 Jasmine 设置 Angular2 Material2 项目。 Here 是我的 karma.conf.js 的链接。我能够为我没有使用 Material2 组件但是当我使用 material2 组件时 Karma 抱怨的组件注入和编写测试。以下是我得到的错误:

Uncaught ReferenceError: require is not defined at C:/Ram Code/node_modules/@angular2-material/button/button.js:16

有人可以帮忙吗?我也尝试过使用其他存储库,例如 this 之一,但没有运气,因为 Karma 仍然抱怨相同。

如果我做错了什么,或者是否有任何可用的存储库可供我参考,有人可以告诉我吗? Karma.conf.js 文件位于:https://gist.github.com/RamVellanki/dbc03cea46eaa6a9ef656badcd1bbc0e

【问题讨论】:

  • 你能显示你的karma 配置吗?谢谢。
  • 抱歉,错过了。刚刚更新了。

标签: angular angular-material karma-runner


【解决方案1】:

您的 Karma 配置的问题在于,您将 Material Components 直接加载到 Karma 内部。

所有这些组件/库,都应该由 SystemJS 自己加载。

例如,您只是将它们映射到您的 SystemJS 配置中。

这是一个示例 SystemJS 配置,在您的情况下应该包含在 Karma 配置中。

  { pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
  { pattern: 'systemjs.config.js', included: true, watched: false},

现在,SystemJS 已正确配置,您可以将它们导入到源文件中。

import { MdButton } from '@angular2-material/button';

因此,您不需要手动导入组件(这不起作用),因为组件是 SystemJS 模块。

【讨论】:

    猜你喜欢
    • 2017-04-17
    • 2018-10-01
    • 2018-12-23
    • 1970-01-01
    • 2017-05-25
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多