ayc0 / mock-match-media Goto Github PK
View Code? Open in Web Editor NEWMock window.matchMedia for Node.JS environments (like tests or NextJS)
License: MIT License
Mock window.matchMedia for Node.JS environments (like tests or NextJS)
License: MIT License
I'm using this library in a jest-based project. I assume the effects of setMedia
persist between tests. If that's the case could you consider 1. an api to reset all properties to default. and 2. call this new api automatically for test environments that have an afterEach hook? (like how RTL does it with cleanup)
In newer versions of V8, .dispatchEvent()
doesn't call anything if it's not a change
event (same in firefox):
In newer versions of V8, using once
doesn't clear listeners that were defined without once
(same in firefox):
Hey @Ayc0 , I know this is not the best place to write this, but thank you for creating this library!
I've tested many different mocks and none was as straightforward as this one, and this solves all problems I'm having to unit test highly dynamic components in various screen sizes.
Again, thanks for all the effort you are putting into this library, you are awesome ❤️
https://github.com/ericf/css-mediaquery only supports the v2 or the v3, but it doesn't support the v4, like (400px <= width <= 600px)
See https://drafts.csswg.org/cssom/#parse-a-media-query-list for more infos
Like #26 but for .onchange
(tested in chrome, safari, and Firefox)
I am using mock-match-media in a Typescript 5.x project and get the following error on type checking:
error TS7016: Could not find a declaration file for module 'mock-match-media'.
'.../node_modules/mock-match-media/dist/index.mjs' implicitly has an 'any' type.
There are types at '.../node_modules/mock-match-media/dist/index.d.ts', but this result
could not be resolved when respecting package.json "exports". The 'mock-match-media' library
may need to update its package.json or typings.
My understanding is, that typescript is expecting type declarations in the exports
section of package.json.
Patching it locally to the following fixes it for me:
"exports": {
".": {
"types": "./dist/index.d.ts", // <--- Added this
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"browser": "./dist/index.mjs"
}
...
Also: the types
declaration in the root of the package.json points to "dist/index.d.js" instead of "dist/index.d.ts".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.