question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Moment not working with Karma unit tests

See original GitHub issue

Expected 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

  1. Run npm install moment-timezone
  2. Include this in the top of your file: import moment from 'moment-timezone';
  3. 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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
maksimrcommented, May 29, 2016

@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

0reactions
leopoldjoycommented, May 29, 2016

@maksimr Thank you for the response! I had moment-timezone installed, I just forgot the --save, sorry. Worked perfectly once commented! 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found