简体   繁体   English

离子2:用茉莉花和业力错误'ng test'测试

[英]Ionic 2 : Test with jasmine and karma error 'ng test'

I try to follow this tutorial : 我尝试遵循本教程:

http://lathonez.com/2017/ionic-2-unit-testing/ http://lathonez.com/2017/ionic-2-unit-testing/

And when I run "ng test" I have this error : 当我运行“ ng test”时,出现此错误:

C:\xampp\htdocs\AppFineMobile>ng test
27 03 2017 11:55:00.556:ERROR [preprocess]: Can not load "angular-cli", it is not registered!
  Perhaps you are missing some plugin?
No provider for "framework:angular-cli"! (Resolving: framework:angular-cli)
Error: No provider for "framework:angular-cli"! (Resolving: framework:angular-cli)
    at error (C:\xampp\htdocs\AppFineMobile\node_modules\di\lib\injector.js:22:12)
    at Object.get (C:\xampp\htdocs\AppFineMobile\node_modules\di\lib\injector.js:9:13)
    at Injector.get (C:\xampp\htdocs\AppFineMobile\node_modules\di\lib\injector.js:54:19)
    at C:\xampp\htdocs\AppFineMobile\node_modules\karma\lib\server.js:143:20
    at Array.forEach (native)
    at Server._start (C:\xampp\htdocs\AppFineMobile\node_modules\karma\lib\server.js:142:21)
    at Injector.invoke (C:\xampp\htdocs\AppFineMobile\node_modules\di\lib\injector.js:75:15)
    at Server.start (C:\xampp\htdocs\AppFineMobile\node_modules\karma\lib\server.js:103:18)
    at Promise (C:\xampp\htdocs\AppFineMobile\node_modules\@angular\cli\tasks\test.js:35:25)
    at Class.run (C:\xampp\htdocs\AppFineMobile\node_modules\@angular\cli\tasks\test.js:15:16)
    at Class.run (C:\xampp\htdocs\AppFineMobile\node_modules\@angular\cli\commands\test.js:99:25)
    at Class.<anonymous> (C:\xampp\htdocs\AppFineMobile\node_modules\@angular\cli\ember-cli\lib\models\command.js:134:17)
    at process._tickCallback (internal/process/next_tick.js:103:7)

I don't understand what I have to do. 我不知道该怎么办。 I had run this command at first : 我刚开始运行此命令:

npm install --save-dev @angular/cli @types/jasmine @types/node jasmine-core jasmine-spec-reporter karma karma-chrome-launcher karma-cli karma-jasmine karma-jasmine-html-reporter karma-coverage-istanbul-reporter

It work well, and I add all file mentioned in the tutorial ... 它工作正常,我添加了教程中提到的所有文件...

In my test.ts file I have an error in my import : 在我的test.ts文件中,我的导入错误:

import { getTestBed, TestBed } from '@angular/core/testing';

I have : Cannot find module '@angular/core/testing', but it exist in my module folder... 我有:找不到模块'@ angular / core / testing',但是它存在于我的模块文件夹中...

Someone have an idea ? 有人有主意吗?

I think your problem is that the karma.conf.js is still pointing at the old angular-cli this has been renamed to @angular/cli . 我认为您的问题是karma.conf.js仍指向已重命名为@angular/cli的旧angular-cli @angular/cli

If you change all the angular-cli to @angular/cli in your karma.conf.js file that should point you in the right direction. 如果您在karma.conf.js文件karma.conf.js所有angular-cli更改为@angular/cli ,这karma.conf.jskarma.conf.js正确的方向。

The format of the karma.conf.js has also changed so it may need to be updated. karma.conf.js的格式也已更改,因此可能需要更新。

For Update docs see https://github.com/angular/angular-cli/wiki/stories-rc.0-update 有关更新文档,请参见https://github.com/angular/angular-cli/wiki/stories-rc.0-update

There looks to be three ways of unit testing ionic 2 projects going around at the moment. 目前似乎有3种方法对ionic 2项目进行单元测试。

  1. angular-cli ( deprecated but works fine for me ) angular-cli (已弃用,但对我来说效果很好)
  2. @angular/cli ( new shiny but tricky to upgrade too if you have an angular-cli setup already ) http://lathonez.com/2017/ionic-2-unit-testing/ @ angular / cli (新的闪亮但如果您已经有angular-cli设置,也很难升级) http://lathonez.com/2017/ionic-2-unit-testing/
  3. Using scripts called by "ionic test" ( see ionic blog for details and link to test example ) http://blog.ionic.io/basic-unit-testing-in-ionic/ 使用“离子测试”调用的脚本(有关详细信息,请参见离子博客,并链接到测试示例) http://blog.ionic.io/basic-unit-testing-in-ionic/

There will soon be another way too 很快也会有另一种方式

ionic blog: "We're also working on baking unit testing right into the Ionic CLI (or more accurately, @ionic/app-scripts). Stay tuned for that." ionic博客:“我们还在Ionic CLI(或更准确地说,@ ionic / app-scripts)中进行烘焙单元测试。敬请关注。”

If you can wait a bit I would wait for Ionic CLI version. 如果可以稍等,我将等待Ionic CLI版本。 It's likely to give you the least amount of problems long run, as the ionic team will keep it running will all the new shiny ionic goodness that comes along. 从长远来看,这可能会给您带来最少的问题,因为离子团队将保持运行,将随之而来的是所有新的闪亮离子优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM