score:0
from this doc: https://developer.mozilla.org/en-us/docs/web/javascript/reference/statements/import
the name parameter is the name of the "module object" which will be used as a kind of namespace to refer to the exports. the export parameters specify individual named exports, while the import * as name syntax imports all of them.
that means if you use import * as io from 'socket.io-client'
, the io
is a kind of namespace.
in your mock file, the io
is an object and export default io;
if you use import * as io from 'socket.io-client'
. the value of io
variable will be:
{ // <- the outer object is io namespace
io: { // <- this is the io object you defined in your mock file
connect() {
return socket;
}
}
}
use import io from 'socket.io-client'
, it will import the default object from it which is:
const io = {
connect() {
return socket;
},
};
if you insist using import * as io from 'socket.io-client'
statement.
change
export const io = {
connect() {
return socket;
},
};
to:
export function connect() {
return socket;
}
and remove export default io;
statement.
Source: stackoverflow.com
Related Query
- Mocked npm module returns empty objects in jest
- Service mocked with Jest causes "The module factory of jest.mock() is not allowed to reference any out-of-scope variables" error
- SpyOn a mocked jest module not spying properly
- jest function mocked from module doesn't detect its call when it is called by other method
- ReactJS component state returns empty data even after being set successfully in jest / enzyme tests
- Mocking react custom hook return value as a module with Jest returns wrong value
- Testing Mocked Fetch Api in Jest returns undefined
- How to mock a variable in ES6 Module with jest such that the actual function runs with mocked value
- How do I Import a manually mocked module with mocked data using jest and enzyme?
- Jest Enzyme test a React component that returns null in render method
- jest + enzyme, using mount(), document.getElementById() returns null on component which appear after _method call
- Jest Could not locate module FileName.css (mapped as identity-obj-proxy)
- Jest Mock User Module in All Test Files
- Jest - SyntaxError: Cannot use import statement outside a module
- Cannot find module 'ReactNative' from 'react-native.js' w/ Jest
- "Define is not defined" in Jest when testing es6 module with RequireJS dependency
- Browserify cannot find npm module
- Jest Test Babel Error: Plugin/Preset files are not allowed to export objects
- How to exclude CSS module files from jest test suites?
- npm install from github: Module not found: Can't resolve 'react-big-calendar'
- asserting against thrown error objects in jest
- Jest fails with error: Cannot find module 'react/lib/ReactComponentTreeHook'
- Why Code Coverage in react app is empty? Tried using npm run test -- --coverage. But always showing empty code coverage
- npm ERR! Object for dependency "@babel/core" is empty
- Editing code of react npm modules in node module folder
- Jest - Cannot find module 'source-map' from 'source-map-support.js'
- Partially mock React module with Jest
- npm start on new create-react-app build returns ELIFECYCLE error
- Jest fails Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js' after React 16 upgrade
- How do I specify module paths for Jest tests?
More Query from same tag
- React useState not updating
- testing conditional rendering that relies on state using react testing library
- Calling React setState from outside of function body
- React performance: rendering big list with PureRenderMixin
- Slick slider render slide multiple times in reactjs
- abort http request on change reactjs
- React: Are there respectable limits to number of props on react components
- how to import whole Material UI library in React JS
- How to bootstrap component using react-router
- How to save local storage cypress react
- Running Mocha on windows for jsx test
- Buidling a custom horz bar chart in superset and adding a custom item to customize chart
- React Martial UI component overwritten/conflicts when new component is loaded
- Issue importing createRoot from react-dom/client
- How to use fetch() in react front-end to get data from express back-end?
- Redux shorthand `mapDispatchToProps` returns undefined for `async` actions / thunks
- Showing 1 of 2 components on button click
- Emitting custom event in React
- Storing Form Data to google sheet using Reactjs
- Why toggleSelection and isSelected method are receiving different key parameter?
- How to redefine a style .tippy-tooltip in "react-tippy"
- What is wrong with dynamic route?
- How do I store firebase Auth data in firestore?
- How to pass data from render method to multiple components in React?
- Adding div elements in ReactJS
- Why am I getting 'undefined:x:y : property' missing error when running jest tests?
- How to limited the countries list in npm react-phone-number-input package
- Why is my reactstrap modal not opening when my button is clicked?
- Leaflet never loads leaving the screen blank with no errors
- react-map-gl Warning onViewportChange