I'm trying to unit test my app and I got message :
Failed: Cannot read property 'Ionic' of undefined
at <Jasmine>
at E (webpack:///node_modules/ionic-angular/config/config.js:363 <- test-config/karma-test-shim.js:956:92100)
at webpack:///node_modules/@angular/core/esm5/core.js:10960 <- test-config/karma-test-shim.js:298:1193
at fi (webpack:///node_modules/@angular/core/esm5/core.js:10910 <- test-config/karma-test-shim.js:298:1349)
at webpack:///node_modules/@angular/core/esm5/core.js:10860 <- test-config/karma-test-shim.js:313:8938
at new t (webpack:///node_modules/@angular/core/esm5/core.js:12115 <- test-config/karma-test-shim.js:313:8948)
at Ri (webpack:///node_modules/@angular/core/esm5/core.js:12104 <- test-config/karma-test-shim.js:313:8601)
at Object.Xo [as createNgModuleRef] (webpack:///node_modules/@angular/core/esm5/core.js:14438 <- test-config/karma-test-shim.js:363:2428)
at e.create (webpack:///node_modules/@angular/core/esm5/core.js:15576 <- test-config/karma-test-shim.js:371:436)
at t._initIfNeeded (webpack:///node_modules/@angular/core/esm5/testing.js:1006 <- test-config/karma-test-shim.js:725:5278)
at t.createComponent (webpack:///node_modules/@angular/core/esm5/testing.js:1138 <- test-config/karma-test-shim.js:725:8455)
at Function.t.createComponent (webpack:///node_modules/@angular/core/esm5/testing.js:837 <- test-config/karma-test-shim.js:725:2576)
at UserContext.<anonymous> (webpack:///src/app/app.component.spec.ts:38:22 <- test-config/karma-test-shim.js:1066:146072)
at t.invoke (webpack:///node_modules/zone.js/dist/zone.js:388 <- test-config/karma-test-shim.js:768:7001)
at t.onInvoke (webpack:///node_modules/zone.js/dist/async-test.js:106 <- test-config/karma-test-shim.js:925:1819)
at t.onInvoke (webpack:///node_modules/zone.js/dist/proxy.js:125 <- test-config/karma-test-shim.js:872:2235)
at t.invoke (webpack:///node_modules/zone.js/dist/zone.js:387 <- test-config/karma-test-shim.js:768:6941)
at e.runGuarded (webpack:///node_modules/zone.js/dist/zone.js:151 <- test-config/karma-test-shim.js:768:2374)
at a (webpack:///node_modules/@angular/core/esm5/testing.js:107 <- test-config/karma-test-shim.js:697:17982)
at UserContext.<anonymous> (webpack:///node_modules/@angular/core/esm5/testing.js:46 <- test-config/karma-test-shim.js:697:17044)
at t.invoke (webpack:///node_modules/zone.js/dist/zone.js:388 <- test-config/karma-test-shim.js:768:7001)
at t.onInvoke (webpack:///node_modules/zone.js/dist/proxy.js:128 <- test-config/karma-test-shim.js:872:2261)
at t.invoke (webpack:///node_modules/zone.js/dist/zone.js:387 <- test-config/karma-test-shim.js:768:6941)
at e.run (webpack:///node_modules/zone.js/dist/zone.js:138 <- test-config/karma-test-shim.js:768:2171)
at l (webpack:///node_modules/zone.js/dist/jasmine-patch.js:142 <- test-config/karma-test-shim.js:910:1303)
at UserContext.<anonymous> (webpack:///node_modules/zone.js/dist/jasmine-patch.js:158 <- test-config/karma-test-shim.js:910:1380)
at <Jasmine>
at t.invokeTask (webpack:///node_modules/zone.js/dist/zone.js:421 <- test-config/karma-test-shim.js:768:7685)
at e.runTask (webpack:///node_modules/zone.js/dist/zone.js:188 <- test-config/karma-test-shim.js:768:2865)
at m (webpack:///node_modules/zone.js/dist/zone.js:595 <- test-config/karma-test-shim.js:768:9934)
Expected false to be true.
webpack.test.js
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [{
test: /\.ts$/,
loaders: [{
loader: 'ts-loader'
}, 'angular2-template-loader']
},
{
test: /.+\.ts$/,
exclude: /(index.ts|mocks.ts|\.spec\.ts$)/,
loader: 'istanbul-instrumenter-loader',
enforce: 'post',
query: {
esModules: true
}
},
{
test: /\.html$/,
loader: 'html-loader?attrs=false'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null-loader'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/(ionic-angular)|(angular(\\|\/)core(\\|\/)@angular)/,
root('./src'), // location of your src
{} // a map of your routes
)
]
};
function root(localPath) {
return path.resolve(__dirname, localPath);
}
I'm trying to unit test my app and I got message :
webpack.test.js
karma.conf.js
karma-test-shim.js
app.component.spec.ts
app.component.js