我尝试用Jasmine和Karma测试我的Ionic 2应用程序。 当我跑'npm test'我有这个错误:
C:\xampp\htdocs\MyApp>npm test
> ionic-hello-world@ test C:\xampp\htdocs\MyApp
> karma start ./test-config/karma.conf.js
webpack: Compiled successfully.
webpack: Compiling...
ts-loader: Using typescript@2.0.9 and C:\xampp\htdocs\MyApp\tsconfig.json
28 03 2017 14:24:17.950:WARN [karma]: No captured browser, open http://localhost:9876/
ERROR in ./src/pages/login/login.html
Module not found: Error: Can't resolve './assets/images/fr.svg' in 'C:\xampp\htdocs\MyApp\src\pages\login'
@ ./src/pages/login/login.html 1:1614-1647
@ ./src/pages/login/login.ts
@ ./src/app/app.component.ts
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts
@ ./test-config/karma-test-shim.js
ERROR in ./src/pages/login/login.html
Module not found: Error: Can't resolve './assets/images/ch.svg' in 'C:\xampp\htdocs\MyApp\src\pages\login'
@ ./src/pages/login/login.html 1:1832-1865
@ ./src/pages/login/login.ts
@ ./src/app/app.component.ts
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts
@ ./test-config/karma-test-shim.js
ERROR in ./src/pages/load-screen/load-screen.html
Module not found: Error: Can't resolve './assets/images/logo-yellow.svg' in 'C:\xampp\htdocs\MyApp\src\pages\load-screen'
@ ./src/pages/load-screen/load-screen.html 1:94-136
@ ./src/pages/load-screen/load-screen.ts
@ ./src/pages/login/login.ts
@ ./src/app/app.component.ts
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts
@ ./test-config/karma-test-shim.js
webpack: Failed to compile.
28 03 2017 14:24:17.974:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
28 03 2017 14:24:17.975:INFO [launcher]: Launching browser Chrome with unlimited concurrency
28 03 2017 14:24:18.036:INFO [launcher]: Starting browser Chrome
28 03 2017 14:24:21.892:INFO [Chrome 56.0.2924 (Windows 10 0.0.0)]: Connected on socket Z7t5AaWcca3yDbsDAAAA with id 37780347
Chrome 56.0.2924 (Windows 10 0.0.0) ERROR
Uncaught Error: Cannot find module "./assets/images/logo-yellow.svg"
at webpack:///src/pages/load-screen/load-screen.html:1:0 <- karma-test-shim.js:150313
Chrome 56.0.2924 (Windows 10 0.0.0) ERROR
Uncaught Error: Cannot find module "./assets/images/logo-yellow.svg"
at webpack:///src/pages/load-screen/load-screen.html:1:0 <- karma-test-shim.js:150313
Chrome 56.0.2924 (Windows 10 0.0.0): Executed 0 of 0 ERROR (1.349 secs / 0 secs)
问题是我的项目中的图像路径。我不明白为什么,但它像模块一样体贴。
事实上,如果我删除了项目中图像的所有路径,那么测试就可以了。但我需要保留我的图片......
我的html中有一个图像路径的例子:
<ion-content padding>
<div class="loading-screen">
<img src="assets/images/logo-yellow.svg"><br><br>
<label>{{this.translate.get('mod-appFine-data_loading')}}</label><br>
<label>{{this.translate.get('mod-appFine-thanks_wait')}}</label><br>
<ion-spinner name="crescent" ></ion-spinner>
</div>
</ion-content>
有人有想法解决这个问题吗?
答案 0 :(得分:0)
我的解决方案是在var中使用right path并在我的代码中调用此var。它对我有用。