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.

How test with Jest?

See original GitHub issue

I’m trying to setup Jest tests configuration for my project. I use imports-loader to load some old jQuery libs

import 'imports-loader!jquery-mousewheel'

When running tests with jest I get following error:

 Cannot find module 'imports-loader!jquery-mousewheel' from 'SomeModule.js'

As a workaround, I mock all imports-loader in Jest config

"moduleNameMapper": {
  "imports-loader?.*": "<rootDir>/internals/mocks/importsLoader.js"
},
// importsLoader.js
module.exports = 'IMPORTS_LOADER_MOCK';

How to configure it to actually import correct module?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nickangtccommented, Dec 21, 2017

Thanks @darkowic I needed just a solution to mock all the require('imports!...') blocks, your moduleNameMapper solution worked for me 👍

0reactions
alexander-akaitcommented, Jun 16, 2020

Here a lot of examples - https://jestjs.io/docs/en/webpack, if somebody still have problems, please open an issue in jest

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest · Delightful JavaScript Testing
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, ......
Read more >
Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >
Jest Testing Tutorial: 5 Easy Steps - Testim Blog
1. Install Jest Globally · 2. Create a Sample Project · 3. Add Jest to the Project · 4. Write Your First Test...
Read more >
Jest Tutorial - JavaScript Unit Testing Using Jest Framework
Jest is a Javascript Testing framework built by Facebook. It is primarily designed for React (which is also built by Facebook) based apps...
Read more >
Testing with Jest
Jest is a Javascript Testing Framework by Facebook. It is used most commonly for unit testing. Unit testing is when you provide input...
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