Aurelia依赖注射测试

时间:2016-05-27 03:16:44

标签: dependency-injection aurelia jspm

我一直在aurelia app工作,我在测试时遇到错误。

我正在尝试使用aurelia-dependency-injection,这已经是我通过jspm aurelia-frameworkaurelia-routeraurelia-templating-resources等其他软件包的依赖项},aurelia-templating-router当我尝试注入它时,我的浏览器工作正常。但是,当我尝试使用Karma进行测试时,它说

27 05 2016 09:45:18.202:WARN [web-server]: 404: /base/aurelia-dependency-injection.js
Chrome 50.0.2661 (Linux 0.0.0) ERROR
Error: XHR error (404 Not Found) loading /home/cyberkiller/test_project/aurelia-dependency-injection.js
Error loading /home/cyberkiller/test_project/aurelia-dependency-injection.js as "aurelia-dependency-injection" from /home/cyberkiller/test_project/src/users/list.ts

我的package.json具有以下jspm依赖项:

  "jspm": {
    "dependencies": {
      "aurelia-animator-css": "npm:aurelia-animator-css@^1.0.0-beta.1.1.2",
      "aurelia-bootstrapper": "npm:aurelia-bootstrapper@^1.0.0-beta.1.1.4",
      "aurelia-fetch-client": "npm:aurelia-fetch-client@^1.0.0-beta.1.1.1",
      "aurelia-framework": "npm:aurelia-framework@^1.0.0-beta.1.1.4",
      "aurelia-history-browser": "npm:aurelia-history-browser@^1.0.0-beta.1.1.4",
      "aurelia-loader-default": "npm:aurelia-loader-default@^1.0.0-beta.1.1.3",
      "aurelia-logging-console": "npm:aurelia-logging-console@^1.0.0-beta.1.1.4",
      "aurelia-pal-browser": "npm:aurelia-pal-browser@^1.0.0-beta.1.1.4",
      "aurelia-polyfills": "npm:aurelia-polyfills@^1.0.0-beta.1.0.3",
      "aurelia-router": "npm:aurelia-router@^1.0.0-beta.1.1.3",
      "aurelia-templating-binding": "npm:aurelia-templating-binding@^1.0.0-beta.1.1.2",
      "aurelia-templating-resources": "npm:aurelia-templating-resources@^1.0.0-beta.1.1.3",
      "aurelia-templating-router": "npm:aurelia-templating-router@^1.0.0-beta.1.1.2",
      "bootstrap": "github:twbs/bootstrap@^3.3.5",
      "fetch": "github:github/fetch@^0.11.0",
      "font-awesome": "npm:font-awesome@^4.6.1",
      "simple-line-icons": "npm:simple-line-icons@^2.2.4",
      "text": "github:systemjs/plugin-text@^0.0.3"
    },
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4"
    }
  }

我确实找到了一种解决方法,即将aurelia-dependency-injection显式添加为package.json中的依赖项

"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.1.2.3"

这使我的package.json看起来像:

"jspm": {
    "dependencies": {
      "aurelia-animator-css": "npm:aurelia-animator-css@^1.0.0-beta.1.1.2",
      "aurelia-bootstrapper": "npm:aurelia-bootstrapper@^1.0.0-beta.1.1.4",
      "aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.1.2.3",
      "aurelia-fetch-client": "npm:aurelia-fetch-client@^1.0.0-beta.1.1.1",
      "aurelia-framework": "npm:aurelia-framework@^1.0.0-beta.1.1.4",
      "aurelia-history-browser": "npm:aurelia-history-browser@^1.0.0-beta.1.1.4",
      "aurelia-loader-default": "npm:aurelia-loader-default@^1.0.0-beta.1.1.3",
      "aurelia-logging-console": "npm:aurelia-logging-console@^1.0.0-beta.1.1.4",
      "aurelia-pal-browser": "npm:aurelia-pal-browser@^1.0.0-beta.1.1.4",
      "aurelia-polyfills": "npm:aurelia-polyfills@^1.0.0-beta.1.0.3",
      "aurelia-router": "npm:aurelia-router@^1.0.0-beta.1.1.3",
      "aurelia-templating-binding": "npm:aurelia-templating-binding@^1.0.0-beta.1.1.2",
      "aurelia-templating-resources": "npm:aurelia-templating-resources@^1.0.0-beta.1.1.3",
      "aurelia-templating-router": "npm:aurelia-templating-router@^1.0.0-beta.1.1.2",
      "bootstrap": "github:twbs/bootstrap@^3.3.5",
      "fetch": "github:github/fetch@^0.11.0",
      "font-awesome": "npm:font-awesome@^4.6.1",
      "simple-line-icons": "npm:simple-line-icons@^2.2.4",
      "text": "github:systemjs/plugin-text@^0.0.3"
    },
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4"
    }
  }

当我更新所有内容并构建并运行测试时,它不再抱怨并且成功执行。但是,我不确定这只是一种解决方法,还是方法。有没有更好的方法来解决这个问题?

先谢谢!

0 个答案:

没有答案