Comments (6)
So - you just have an issue with importing ESModules from node_modules, that’s absolutely ok-ish.
By default, even if you are running your tests with Babel/register, it will ignore node_modules. So, as long as Babel won’t transpile code, and node won’t understand imports - it does not work.
How to solve:
- or change Babel configuration (I am not sure how)
- use ‘esm_modules’ from require-control, that would save your day.
from rewiremock.
thanks, sorry I'm not sure to understand as I'm quite new to Javascript and React, I tried the following in my test script but this didn't work:
require('babel-register');
const { esm_modules } = require('require-control');
esm_modules();
from rewiremock.
Sorry, I've read your issue a bit inaccurate - the original problem import './mycompoent.css';
is happening in your own mycomponent.js
.
That means that babel-register
is not working as expected. Probably you have modules:false
setting in your .babelrc
- could you please check it?
from rewiremock.
./node_modules/babel-plugin-dynamic-import-node/.babelrc:
-------------------------------------------------
{
"presets": [
"airbnb"
],
"plugins": [
"add-module-exports",
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
],
}
./node_modules/compare-module-exports/.babelrc:
-------------------------------------------------
{
"presets": [],
"env": {
"cjs": {
"presets": [
[
"env",
{
"targets": {
"node": "7.0",
"ie": 11
}
}
]
]
}
}
}
./node_modules/eslint-plugin-jsx-a11y/.babelrc:
-------------------------------------------------
{
"presets": ["es2015"],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types",
]
}
./node_modules/esrecurse/.babelrc:
-------------------------------------------------
{
"presets": ["es2015"]
}
./node_modules/estraverse/.babelrc:
-------------------------------------------------
{
"presets": ["es2015"]
}
./node_modules/fileset/.babelrc:
-------------------------------------------------
{
"presets": ["es2015"],
"plugins": [
"add-module-exports"
]
}
./node_modules/identity-obj-proxy/.babelrc:
-------------------------------------------------
{
"presets": [ "es2015", "stage-0" ],
}
./node_modules/jsx-ast-utils/.babelrc:
-------------------------------------------------
{
"presets": ["es2015"]
}
./node_modules/optimize-css-assets-webpack-plugin/.babelrc:
-------------------------------------------------
{
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "current"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
]
}
./node_modules/wipe-node-cache/.babelrc:
-------------------------------------------------
{
"presets": [],
"env": {
"cjs": {
"presets": [
[
"env",
{
"targets": {
"node": "7.0",
"ie": 11
}
}
]
]
}
}
}
./node_modules/wipe-webpack-cache/.babelrc:
-------------------------------------------------
{
"presets": [],
"env": {
"cjs": {
"presets": [
[
"env",
{
"targets": {
"node": "7.0",
"ie": 11
}
}
]
]
}
}
}
Also note I'm using create-react-app
, I didn't change any config so far but I have no clue if they're doing something special...
Thanks !
from rewiremock.
ok, not it's clear why it's not working - there is no setup for a babel.
If you are using CRA
and running npm run test
, then according to the documentation you should have Jest.
Jest should handle babel out of the box, and also should handle mocking (via jest.mock).
! rewrimock
is incompatible with Jest
In the same time - as long as you were able to mock something, and have babel related issues - it's not the default CRA config.
Then - just drop .babelrc
to your tests or root dirrectory
{
presets: ["env","react"]
}
from rewiremock.
Thanks for your help, sorry I need to use react-app-rewired
to be able to customize babelrc
, I don't have time right now I'm gonna try this a little bit later asap...
from rewiremock.
Related Issues (20)
- Is it possible to make multiple hot mock updates? HOT 2
- Documentation Needed: jest.mock Equivalent HOT 1
- Please add a test for a module that returns a Class that gets newed up by the SUT HOT 1
- Something like cache problem HOT 3
- Testing a private function using rewiremock HOT 2
- Mocking non existent modules HOT 4
- how to use in webpack5
- Angular 11
- Usage inquiry ES6 HOT 1
- webpack.NamedModulesPlugin() has been deprecated HOT 12
- Configuration for Mocha/webpack5 HOT 1
- nodejs v18.3.0 Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins? HOT 3
- Typescript setup Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins?
- Mock called, but not stubbing dependency HOT 2
- Invoking 'proxy' to generate test object but stub not invoked HOT 3
- Is it enable can execute like a jest.mock? HOT 3
- Setup for multiple test files HOT 4
- Does rewiremock work with ts-node? HOT 3
- Question: Mocking local variable in the scope of original module HOT 1
- Ts-node and rewiremock HOT 2
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 rewiremock.