{"_id":"jest-matchmedia-mock","_rev":"3-471c0810720296bf416b54472856a62f","name":"jest-matchmedia-mock","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"jest-matchmedia-mock","description":"Mock for fully testing any media queries with Jest","version":"1.0.0","license":"MIT","author":{"name":"Kirill Dyakov"},"repository":{"type":"git","url":"git+https://github.com/dyakovk/jest-matchmedia-mock.git"},"bugs":{"url":"https://github.com/dyakovk/jest-matchmedia-mock/issues"},"homepage":"https://github.com/dyakovk/jest-matchmedia-mock#readme","keywords":["jest","mock","jest-mock","jest-matchmedia","matchmedia-mock","window.matchmedia","mediaquery","media query mock","typescript"],"engines":{"node":">=10"},"main":"./dist/matchmedia-mock.js","types":"./dist/matchmedia-mock.d.ts","scripts":{"compile":"rimraf ./dist/ && tsc -p ./tsconfig.prod.json","lint":"eslint ./src/ --ext ts","test":"jest ./src/ --config ./jest.config.json","test:coverage":"jest --config ./jest.config.json --coverage --coverageReporters=text","test:coveralls":"jest --config ./jest.config.json --coverage --coverageReporters=text-lcov | coveralls"},"peerDependencies":{"jest":">=13"},"devDependencies":{"@commitlint/cli":"^8.3.5","@commitlint/config-conventional":"^8.3.4","@types/jest":"^25.1.1","@typescript-eslint/eslint-plugin":"^2.19.0","@typescript-eslint/parser":"^2.19.0","coveralls":"^3.0.9","eslint":"^6.8.0","eslint-config-airbnb-base":"^14.0.0","eslint-config-prettier":"^6.10.0","eslint-plugin-import":"^2.20.1","eslint-plugin-prettier":"^3.1.2","husky":"^4.2.1","jest":"^24.9.0","lint-staged":"^10.0.7","prettier":"^1.19.1","rimraf":"^3.0.1","ts-jest":"^24.3.0","typescript":"^3.7.5"},"gitHead":"58079bff0e6bf1ed7f175ba0ecf9e437aea2edb8","_id":"jest-matchmedia-mock@1.0.0","_nodeVersion":"12.10.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-5ESRUthdlBZwigq5ayEGl8VKM82jlnoLddSk6pOTVUm09ZouDFTCV3grfuZlM9oDfd3yUbJQjV30B7lW3vNctA==","shasum":"ca8b82a2b667f6cc2f8604d519fd4b903c52bfaf","tarball":"https://registry.npmjs.org/jest-matchmedia-mock/-/jest-matchmedia-mock-1.0.0.tgz","fileCount":5,"unpackedSize":11683,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeOYNSCRA9TVsSAnZWagAAHLYP/3KZF7VEB9I8NKFcEDhd\n2wZz3Xmigo1EQ0wRBP9VXfxtve1IalGG0kZAMm3ythvpMWkjenp1ohhXtim+\nuhnK9F+FQ8oTzX5dAefqVubHg67Z8zxl8E6uPfk2B1j0NYryxOiE0Y2YKyhe\njEvAb8wHhFNjokdxLm6U8Z3qkRegp0eLwqavcDcW4sKHe7+PhNDKY4LNifFE\nQ4+FofSOQqlReJ7eGlN6XD8BMWwE6tMgSmCqneaQNV3cRIUD3XgYn+Kqdkqx\nhp+l5gkTrGbspFVZi6GTVeXotz2HEwB/0w2bDywB/T86ESX/tDV9XO2aaTEe\nnrFL+pAtn/lgQlPgO3KsnySIb1U54i3jVhkHe737HkD+rq4Y+SrXodbw3qH/\nvBZuByKbmRNd4Z+cDP5QmMpfu58CDMuHPzyKR+m8aTIrRgkuzeTzyTkD26Xx\nt1n+5DUX0yMMe6fEjGdxU32mEAv9WyiOaU2RYsvIyMRIC3aXH+BTspm1rjM9\nakkhat6ZE7U/+QiRoYCGh6iMnX4hIheQln5R7kJ3Vn3HIicc349ajQT/e4jp\nW00O1KQyhl6+6Bv1sCdp9an1+jPS/5fOUp7PsINHVqG0oq8a9jCjol6k6rKk\n4gLPKWp0TQKjXcjS/tQXfBorNH0jeFbPs2p84GC4SyFrnQaM582ItkuoT/9R\nppkk\r\n=aRB6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHGqP3VY2po+ZnisBPww//pBQvzUZy//ptvlV2IcxxWbAiB4lh64pESmsQfHIRWmSkc3vb6LzkMJnN71mBVHp/H4hg=="}]},"maintainers":[{"name":"dyakovk","email":"dyak.kir@gmail.com"}],"_npmUser":{"name":"dyakovk","email":"dyak.kir@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jest-matchmedia-mock_1.0.0_1580827473273_0.6206778825321897"},"_hasShrinkwrap":false},"1.0.1":{"name":"jest-matchmedia-mock","description":"Mock for fully testing any media queries with Jest","version":"1.0.1","license":"MIT","author":{"name":"Kirill Dyakov"},"repository":{"type":"git","url":"git+https://github.com/dyakovk/jest-matchmedia-mock.git"},"bugs":{"url":"https://github.com/dyakovk/jest-matchmedia-mock/issues"},"homepage":"https://github.com/dyakovk/jest-matchmedia-mock#readme","keywords":["jest","mock","jest-mock","jest-matchmedia","matchmedia-mock","window.matchmedia","mediaquery","media query mock","typescript"],"engines":{"node":">=10"},"main":"./dist/matchmedia-mock.js","types":"./dist/matchmedia-mock.d.ts","scripts":{"compile":"rimraf ./dist/ && tsc -p ./tsconfig.prod.json","lint":"eslint ./src/ --ext ts","test":"jest ./src/ --config ./jest.config.json","test:coverage":"jest --config ./jest.config.json --coverage --coverageReporters=text","test:coveralls":"jest --config ./jest.config.json --coverage --coverageReporters=text-lcov | coveralls"},"peerDependencies":{"jest":">=13"},"devDependencies":{"@commitlint/cli":"^8.3.5","@commitlint/config-conventional":"^8.3.4","@types/jest":"^25.1.1","@typescript-eslint/eslint-plugin":"^2.19.0","@typescript-eslint/parser":"^2.19.0","coveralls":"^3.0.9","eslint":"^6.8.0","eslint-config-airbnb-base":"^14.0.0","eslint-config-prettier":"^6.10.0","eslint-plugin-import":"^2.20.1","eslint-plugin-prettier":"^3.1.2","husky":"^4.2.1","jest":"^25.1.0","lint-staged":"^10.0.7","prettier":"^1.19.1","rimraf":"^3.0.1","ts-jest":"^25.2.1","typescript":"^3.7.5"},"gitHead":"fe35c4247d8228d259eb816e05ddde57f7ac4a43","_id":"jest-matchmedia-mock@1.0.1","_nodeVersion":"12.10.0","_npmVersion":"6.14.2","dist":{"integrity":"sha512-IXk2AnldfsCRmhB4pFY0Eb9mk2NxFqOgOwA4DxKOJ22T5bn/j3DzM5s3cdKxuEowmpuXK1gPXAIlVGIC+kb/fA==","shasum":"da1c75be82a3b3e46e6c8ae195aa54e4a6032eb4","tarball":"https://registry.npmjs.org/jest-matchmedia-mock/-/jest-matchmedia-mock-1.0.1.tgz","fileCount":5,"unpackedSize":11597,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeb0OZCRA9TVsSAnZWagAAmzAQAIwfKMUwRBAut4vzXyY1\nA0nbqajd6C3E/7FKqfLP70xhD94YuaMWTru01pPOipc+MWvpJjI9tA4bXr+l\nmB4MR8/xBiJckOaIYaLQkSmgKIqTehUj40vU/sHaXHRVkVh5HstrN0Ua6goC\nIOTl4/UuY2iPxhRW1w5e+u0dJPSeGbkXQPNObRHFU5V8PD+bGZXJTMkFrbMD\nG0hOB5XMz0IAv3o7NXm6QKZlUDL/vdnW+nhP2C28PSsH6pRgU05o5goP7Con\nzpKuD14vq9bF2ZTYQdLasIyRlUieQxzLgaxuKD05xG2iHjH69+9PP/Ou0CQ6\n7waA7xpSTZuV0FlneeBe9T+gNEJ6QSNlOVGsDfDDzxl54sClxvJBptIQe1YL\n7Vct4W7HA2Slf4zM3U05dtHWcJY/nNVAFzSNofIdThJGEvEkJyJQKSuwOBLU\ntMdyt6iMfRBVBOPdPFXLDSoduIJpX3prSgwXf5PgVQFh2zGk2UfNGuUxmExV\nuGKPw69XQ/053tggSyuRvpkrUIA6abWard8dBPVHUkTTCZNstlrPfkPyAtO/\nIJdOc5b918iChVswaf/6h91neX1X6OZPjfcFS+gWVJie8Ac5cuksMeKQGEG6\nUxbdNBy2Mz1ueA+TcGCkpw/wKu7urGnnIDrVaPruj+P+KArr/4C5ForwJZqN\nNmBk\r\n=eiZb\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAWShkwpzrubG7FMynBPfbWsSDm6RtLIxp1UBxEkqp/TAiAJ9hhL1hKOy3RXura7av0tTu9I3NSj+Pbr8rTlXxASHg=="}]},"maintainers":[{"name":"dyakovk","email":"dyak.kir@gmail.com"}],"_npmUser":{"name":"dyakovk","email":"dyak.kir@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jest-matchmedia-mock_1.0.1_1584350104486_0.9387758568585893"},"_hasShrinkwrap":false},"1.1.0":{"name":"jest-matchmedia-mock","description":"Mock for fully testing any media queries with Jest","version":"1.1.0","license":"MIT","author":{"name":"Kirill Dyakov"},"repository":{"type":"git","url":"git+https://github.com/dyakovk/jest-matchmedia-mock.git"},"bugs":{"url":"https://github.com/dyakovk/jest-matchmedia-mock/issues"},"homepage":"https://github.com/dyakovk/jest-matchmedia-mock#readme","keywords":["jest","mock","jest-mock","jest-matchmedia","matchmedia-mock","window.matchmedia","mediaquery","media query mock","typescript"],"engines":{"node":">=10"},"main":"./dist/matchmedia-mock.js","types":"./dist/matchmedia-mock.d.ts","scripts":{"compile":"rimraf ./dist/ && tsc -p ./tsconfig.prod.json","lint":"eslint ./src/ --ext ts","test":"jest ./src/ --config ./jest.config.json","test:coverage":"jest --config ./jest.config.json --coverage --coverageReporters=text","test:coveralls":"jest --config ./jest.config.json --coverage --coverageReporters=text-lcov | coveralls"},"peerDependencies":{"jest":">=13"},"devDependencies":{"@commitlint/cli":"^9.1.2","@commitlint/config-conventional":"^9.1.1","@types/jest":"^26.0.8","@typescript-eslint/eslint-plugin":"^3.8.0","@typescript-eslint/parser":"^3.8.0","coveralls":"^3.0.9","eslint":"^7.6.0","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.10.0","eslint-plugin-import":"^2.22.0","eslint-plugin-prettier":"^3.1.2","husky":"^4.2.1","jest":"^26.2.2","lint-staged":"^10.2.11","prettier":"^2.0.5","rimraf":"^3.0.1","ts-jest":"^26.1.4","typescript":"^3.9.7"},"gitHead":"3eaac4674a579294459c3c64c017b50c52949373","_id":"jest-matchmedia-mock@1.1.0","_nodeVersion":"12.10.0","_npmVersion":"6.14.7","dist":{"integrity":"sha512-REnJRsOSCMpGAlkxmvVTqEBpregyFVi9MPEH3N83W1yLKzDdNehtCkcdDZduXq74PLtfI+11NyM4zKCK5ynV9g==","shasum":"eaae8c5d1dee4e4f7c59f8cb1b38b5d7ea842552","tarball":"https://registry.npmjs.org/jest-matchmedia-mock/-/jest-matchmedia-mock-1.1.0.tgz","fileCount":5,"unpackedSize":11838,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfKvCuCRA9TVsSAnZWagAA9swP/ildeb0TQI7lu1oBEaHo\n2zcGjksWz3V8Ws0kXDci6/jckepGdxBOFmIZc0VxHuE6ABgOOivjXvljGrem\nhxKROsQiS3agS2OIhJ8j00EIrcT1pnpt6yl1CkPLqi23J5R41KfMxmkz2gxO\nHszeTpfUIrcG5F9Ff52j8a4dusAWQ5KML0iD1U8cUm6EtqWTd2omBY/PBiIX\nGZKhkkVh+Loh6YIumNqkENlLy97kuI1GnB1HiuVM+EXaTCzJWBEdMN+OX+v8\nujACsfRpg6lTclDEB5l1L2ac0PBKnm//CLUNYsLWjBrvqygiJg6SRg25ek3n\nnfrRzoBG5OIE5AZBJVk0QmRNP1E/80byW/djb+U2TT/X/UQK9dJpHCrrYaye\nkrrnqGQtDkr2BNixyHK/M32Zlg85kfWz3doeW+OdUnHJsdf01mg2dB3CZoBO\nondEFahD39eszF9ItyZ9ColKywE9ndpeyaiWb9rjoVZ9ehSS/AgJRV+b63W3\nYIShKqhLfGbhe5wRfcqxAqdF97JKFwAl1m9YDsdmKsSb2WJETiz16lYJ1M0Z\nb23Y6sBrb0dkP5BVOmcQNL38f/rfTywuyasdYYhYbSLPbx9/d2lVQZaacfws\nFFIGoBVFa1uxOvZNZYSC5fOITUjNn9X4ML5gfRgvR7lvSLGG/VSiKnR9YSNl\nC+T4\r\n=Bv/5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB/ZyXjtTG0WGZfs2u0QBCdU0si/2IZRfDMbDd82/dUCAiEAp+06QOtDSUim61NpsTrA4T++pIWFNu1X5eDesTgYnU8="}]},"maintainers":[{"name":"dyakovk","email":"dyak.kir@gmail.com"}],"_npmUser":{"name":"dyakovk","email":"dyak.kir@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jest-matchmedia-mock_1.1.0_1596649645920_0.3155625986620838"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-04T14:44:33.273Z","1.0.0":"2020-02-04T14:44:33.676Z","modified":"2022-05-06T12:33:52.574Z","1.0.1":"2020-03-16T09:15:04.670Z","1.1.0":"2020-08-05T17:47:26.030Z"},"maintainers":[{"name":"dyakovk","email":"dyak.kir@gmail.com"}],"description":"Mock for fully testing any media queries with Jest","homepage":"https://github.com/dyakovk/jest-matchmedia-mock#readme","keywords":["jest","mock","jest-mock","jest-matchmedia","matchmedia-mock","window.matchmedia","mediaquery","media query mock","typescript"],"repository":{"type":"git","url":"git+https://github.com/dyakovk/jest-matchmedia-mock.git"},"author":{"name":"Kirill Dyakov"},"bugs":{"url":"https://github.com/dyakovk/jest-matchmedia-mock/issues"},"license":"MIT","readme":"# 🃏 MatchMedia Mock for Jest\n\n![Travis (.org)](https://img.shields.io/travis/dyakovk/jest-matchmedia-mock)\n![Coveralls github](https://img.shields.io/coveralls/github/dyakovk/jest-matchmedia-mock)\n![npm](https://img.shields.io/npm/dw/jest-matchmedia-mock)\n![GitHub top language](https://img.shields.io/github/languages/top/dyakovk/jest-matchmedia-mock?label=typescript&logo=typescript)\n![npm type definitions](https://img.shields.io/npm/types/jest-matchmedia-mock)\n![node](https://img.shields.io/node/v/jest-matchmedia-mock)\n![npm peer dependency version](https://img.shields.io/npm/dependency-version/jest-matchmedia-mock/peer/jest)\n\nThis implementation of the `window.matchMedia` method allows you to control your media queries and their listening functions. You can update the media query that is currently applied to the document by simply calling one function.\n\n## Installation\n\nNPM\n\n```bash\nnpm i --save-dev jest-matchmedia-mock\n```\n\nYarn\n\n```bash\nyarn add --dev jest-matchmedia-mock\n```\n\n## Usage\n\n```javascript\nimport MatchMediaMock from 'jest-matchmedia-mock';\n\nlet matchMedia;\n\ndescribe('Your testing module' => {\n  beforeAll(() => {\n    matchMedia = new MatchMediaMock();\n  });\n\n  afterEach(() => {\n    matchMedia.clear();\n  });\n\n  test('Your test case', () => {\n    const mediaQuery = '(prefers-color-scheme: light)';\n    const firstListener = jest.fn();\n    const secondListener = jest.fn();\n    const mql = window.matchMedia(mediaQuery);\n\n    mql.addListener(ev => ev.matches && firstListener());\n    mql.addListener(ev => ev.matches && secondListener());\n\n    matchMedia.useMediaQuery(mediaQuery);\n\n    expect(firstListener).toBeCalledTimes(1);\n    expect(secondListener).toBeCalledTimes(1);\n  })\n})\n```\n\nThis works if `window.matchMedia()` is used in a function (or method) which is invoked in the test. If `window.matchMedia()` is executed directly in the tested file, Jest returns `TypeError: window.matchMedia is not a function` and doesn't properly execute the test.\n\nIn this case, the solution is to move the instantiation of the mock into a separate file and include this one in the test before the tested file:\n\n```javascript\nimport matchMedia from './matchMedia.mock.ts'; // Must be imported before the tested file\nimport { myMethod } from './file-to-test';\n\ndescribe('myMethod()', () => {\n  // Test the method here...\n});\n```\n\n## API\n\n### `new MatchMediaMock()`\n\nImplements `window.matchMedia` and returns an instance with methods listed below\n\n### `matchMedia.useMediaQuery()`\n\nUpdates the currently used media query, and calls previously added listener functions registered for the passed media query\n\n- Arguments:\n\n  - `mediaQuery: string;`\n\n- Returns: `never | void`\n\n### `matchMedia.getMediaQueries()`\n\nReturns an array listing the media queries for which the matchMedia has registered listeners\n\n- Returns: `string[]`\n\n### `matchMedia.getListeners()`\n\nReturns a copy of the array of listeners for the passed media query\n\n- Arguments:\n\n  - `mediaQuery: string;`\n\n- Returns: `MediaQueryListener[]`\n\n### `matchMedia.clear()`\n\nClears all registered media queries and their listeners\n\n### `matchMedia.destroy()`\n\nClears all registered media queries and their listeners, and destroys the implementation of `window.matchMedia`\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2020-present, Kirill Dyakov\n","readmeFilename":"README.md"}