【问题标题】:Issues with Http testing (MockBackend, MockConnection) after Angular2 update in KarmaKarma 中 Angular2 更新后的 Http 测试问题(MockBackend、MockConnection)
【发布时间】:2015-12-14 13:12:09
【问题描述】:

在将 Angular2 更新到最新版本(alpha 53)后,我遇到了在 Karma 中导入与测试 Http 服务相关的文件的问题。我在 Karma 中有这样的参考资料:

files: [
    {pattern: 'node_modules/systemjs/dist/system.js', included: true, watched: true},
    {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true},
    {pattern: 'node_modules/angular2/bundles/testing.js', included: true, watched: true},
    {pattern: 'node_modules/  angular2/bundles/http.js', included: true, watched: true},
    {pattern: 'karma-test-shim.js', included: true, watched: true}]

我知道 MockBackend、MockConnection 从 angular2/http 移动到 angular2/http/testing,我的问题是我不知道如何导入这些移动的类,因为我在 bundles 文件夹(或整个angular2 目录),类似于 http-testing.js 或类似的东西,我无法在任何存在的捆绑文件中找到它。

有没有办法解决这个问题?

【问题讨论】:

  • 我不明白你的问题。您已经知道这些类在哪里,但不知道从哪里导入它们?从angular2/http/testing 导入它们就足够了。
  • 是的,IDE 可以识别并编译它们,但是当 Karma 需要获取用于加载所有角度依赖项的具体文件时。所有需要的类都在 bundles 文件夹中,但是新移动的 http/testing 类在 bundles 文件夹中不可用...
  • 我明白了,您是否尝试过直接从它们的路径导入它们?就像在这个file.

标签: angular


【解决方案1】:

从 beta 0 开始,MockBackend/Connection 是 testing.dev.js 包的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 2016-09-07
    • 2014-01-10
    • 2017-08-23
    • 1970-01-01
    相关资源
    最近更新 更多