I am not sure why importing GA into my unit test fails. How can I fix this?
Maybe the JEST error should point me into the right direction, but unfortunately it does not:
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
....
/Users/me/app/node_modules/@ionic-native/google-analytics/index.js:20
import { Injectable } from '@angular/core';
^^^^^^
SyntaxError: Unexpected token import
2 | import { Http } from '@angular/http';
3 | import { Events } from 'ionic-angular';
> 4 | import { GoogleAnalytics } from '@ionic-native/google-analytics';
By instruction I extended my package.json
with
"transformIgnorePatterns": [
"<rootDir>/node_modules"
],
but it still fails with the same error
I think I have found a solution to this problem,
npm run eject
in your code base,package.json
test command as given below,
--env=jsdom --transformIgnorePatterns 'node_modules/(?!(@ionic|<other-package-need-to-transform>)/)
this solution is common for ionic/react and ionic/angular
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With