在Ionic3应用程序中配置单元测试

时间:2018-03-17 15:00:05

标签: ionic3 karma-runner karma-jasmine karma-webpack

我基于以下示例项目在ionic3项目中实现单元测试:https://github.com/ionic-team/ionic-unit-testing-example

它工作正常,但我有一些问题:

  • 我可以看到编译错误(对于jasmine),而这些错误不会阻止运行测试

    karma start ./test-config/karma.conf.js
    webpack: Compiled successfully.
    webpack: Compiling...
    
    17 03 2018 15:53:18.403:WARN [karma]: No captured browser, open http://localhost:9876/
    
    ERROR in ./src/pages/test/test.spec.ts
    [tsl] ERROR in /home/app-path/src/pages/test/test.spec.ts(11,1)
    TS2304: Cannot find name 'describe'.
    
    ERROR in ./src/pages/test/test.spec.ts
    [tsl] ERROR in /home/app-path/src/pages/test/test.spec.ts(17,3)
    TS2304: Cannot find name 'beforeEach'.
    
    ERROR in ./src/pages/test/test.spec.ts
    [tsl] ERROR in /home/app-path/src/pages/test/test.spec.ts(40,39)
    TS2304: Cannot find name 'expect'.
    
    ERROR in ./src/pages/test/test.spec.ts
    [tsl] ERROR in /home/app-path/src/pages/test/test.spec.ts(42,3)
    TS2304: Cannot find name 'it'.
    
    ...
    
    webpack: Failed to compile.
    17 03 2018 15:53:18.422:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
    17 03 2018 15:53:18.422:INFO [launcher]: Launching browser Chrome with unlimited concurrency
    17 03 2018 15:53:18.748:INFO [launcher]: Starting browser Chrome
    17 03 2018 15:53:20.153:INFO [Chrome 57.0.2987 (Linux 0.0.0)]: Connected on socket py7H3olXgBzYBE2DAAAA with id 24040166
    Chrome 57.0.2987 (Linux 0.0.0): Executed 8 of 8 SUCCESS (2.716 secs / 0 secs)
    
  • 即使我配置了kjhtml报告器,也无法在karma启动的浏览器中显示结果。见https://github.com/ionic-team/ionic-unit-testing-example/blob/master/test-config/karma.conf.js#L52。注意我添加了progress记者,它运行正常:

    reporters: ['progress', 'kjhtml'],
    

感谢您的帮助!

0 个答案:

没有答案