New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AppInsightsModule.js is blocking my ability to mock for unit testing (using Jest). #476
Comments
This was fixed in #486 and will be released in v1.0.10 later this week. |
@KamilSzostak I still get this in v1.0.11. Our previously working karma-webpack suite has suddenly started breaking.
|
Other users are also reporting this #518. |
@KamilSzostak any update on when this will be fixed? or how it could be temporarily silenced for now? |
I am experiencing the same issue here. Could the solution be to switch to commonjs?
tbh, not beeing able to run tests with this module is a show stopper. Anyone got a workaround for this? I am running tests like this:
I've tried using amdefine, with no success:
Resulting in:
|
Got a workaround for this: Create a helper with global definition
Use it in script:
|
For jest, you can add:
to your Jest configuration file, and then create a file by following @phun-ky'method. |
This is also an issue using karma in an angular project. Can someone look into it please. |
Error: Will try the workaround, please fix |
+1, I'm running into this error with I'm not sure how to workaround this from the TypeScript context. Please advise. package.json (trimmed)
Usage
|
Still seeing this issue: I'm using Angular 5, Jest and the microsoft-applicationinsights-angular5 but it references back to the JS. It all workd prefect in the app but can't make it work in my unit tests. Does anyone have a solution? |
If you're using jest, adding an empty |
I'm having the same issue. (applicationinsights-js v1.0.18) I've added the empty file and that error is gone. But now the following error is shown when running the tests: 'Cannot read property 'startTrackPage' of undefined'. What do I have to do to fix this error? |
Adding the empty file gives me a |
What my colleague did to solve the problem in a quick hack way was to wrap the AppInsights commands affect in an |
I have created a wrapper around the library as a workaround. Now I can mock the wrapper functions. It is not the best solution... but it works :-) |
You can also use babel-plugin-transform-amd-to-commonjs to transpile Application Insights to CommonJS upon import. Here is a little project using Jest as an example. Related issue: Support for CommonJS #301 |
In Jest there is the moduleNameMapper configuration that can resolve this.
Then in myFakeAppInsights (ts or js) export the methods you are using:
|
This is also happening when trying to integrate with Angular applications as well. |
I am using create-react-app with typescript. The combination of @adeogunsamuel 's suggestion and @barrymichaeldoyle 's suggestion is what worked for me. Thank you! |
This packaging/transpilation problem should be solved by ApplicationInsights SDK v1.0, which is now still in beta and can be installed issuing If you're using React you might also find useful |
I was able to solve this by adding in your jest config add then in app-test-insights.js add |
You need to mock appinsights at the highest possible level you use it, in my case, it is the react wrapper withTracking method:
"react-appinsights": "^2.0.2" |
The versions 1.0.x of the SDK only allow AMD consumers to work. Version 2.0.x-beta (in beta currently, latest public version is 1.0.0-beta-12) supports UMD (if you look in the npm package, we drop distributables in the following formats): /browser: intended to be used for browser (UMD) Please try this out to see if issue still persists. |
To be added, the function is called
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi there,
I am trying to set up jest for my application built using React. I am using ApplicationInsights-js however, whenever I try to run my tests, I keep getting "define is undefined" on any of my tests using components that import ApplicationInsights.
We are using the current version (1.0.9) and the only solution that I have come up with was to comment out the define() function.
Thanks!
The text was updated successfully, but these errors were encountered: