Comments (3)
I honestly try to avoid having to mock entire modules. It might be better to pass the dependency as a constructor or function param instead of directly requiring it. This way mocking becomes easier since you don't have to bypass the whole module system.
Anyway, I'm a big fan of Jest to run tests, and I know it provides a way to mock modules as well. Might be good to have a look: https://jestjs.io/docs/en/es6-class-mocks
cheers!
from mock-loader.
Hi There, I unfortunately don't have an example project for you. Just to give you some context, I've written this webpack plugin quite some time ago to help with the requirejs > webpack migration of a large project I was working on back then. We've only used this plugin very shortly since after the initial migration we converted the whole codebase to make use of ES6 modules.
This loader is build to use with webpack 1, I'm not sure if it will work with newer versions of webpack. The loader is indeed a commonjs module since that is how you were supposed to create webpack plugins at the time.
As far as I can remember, the only thing that you need to do is npm install mock-loader
and webpack will automatically resolve modules using the loader when prefixed with mock!
https://devdocs.io/webpack~1/loaders
hope this helps!
from mock-loader.
Thank you for the fast answer. How do you unit test and mock your ES6 modules? Is there a way to do it without translating it to ES5 with webpack?
from mock-loader.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mock-loader.