Moment not working with Karma unit tests
See original GitHub issueExpected behavior
I expected all of my unit tests to run properly, as they do when I do not include moment-timezone
in my component that is being tested by Karma.
Actual behaviour
None of my tests run and instead I get this error:
START:
Chrome 50.0.2661 (Mac OS X 10.9.2) ERROR
Uncaught Error: Cannot find module "./data/packed/latest.json"
at /Users/myuser/myapp/tests.webpack.js:50215 <- webpack:///~/moment-timezone/index.js:2:0
Chrome 50.0.2661 (Mac OS X 10.9.2) ERROR
Uncaught Error: Cannot find module "./data/packed/latest.json"
at /Users/myuser/myapp/tests.webpack.js:50215 <- webpack:///~/moment-timezone/index.js:2:0
Enviroment Details
- Karma version (output of
karma --version
): 0.13.22
Steps to reproduce the behaviour
- Run
npm install moment-timezone
- Include this in the top of your file:
import moment from 'moment-timezone';
- Include this in your component:
console.log(moment.tz.guess());
NOTE: This is a duplicate of this issue filed on the moment-timezone
GitHub page.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to use momentJs in Karma/Jasmine unit tests for ...
I am trying to write unit tests and I keep getting issues with moment. Here is my config file: // list of files...
Read more >Unit test failing when using moment.js · Issue #3062 - GitHub
I'm including moment.js in my karma.conf.js file. I know it's being picked up properly because moment() is defined, but it fails when it...
Read more >Jasmine: How to unit test my date filters that uses moment.js?
[Solved]-Jasmine: How to unit test my date filters that uses moment.js?-moment.js ... If you mock momentjs functions, you can run into issues in...
Read more >Angular Unit Testing performance - Medium
Now we are ready to define the problem — we would like to compile angular components only once per suite, however angular forces...
Read more >15 Things To Cover When Writing Unit Tests in Jasmine
This means it's currently not possible to test the On-Push behaviour. The only thing we can do at the moment is just to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@leopoldjoy thanks,
first of all you have forgotten install moment-timezone (npm install --save-dev moment-timezone) here
Problem in webpack config which you set in karma.config.js. In your configuration for test you ignore json files but moment-timezone require json file. To fix your problem simple remove or comment ignore plugin
Thanks
@maksimr Thank you for the response! I had
moment-timezone
installed, I just forgot the--save
, sorry. Worked perfectly once commented! 👍