File tree 2 files changed +8
-6
lines changed
website/versioned_docs/version-23.x
2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -141,8 +141,9 @@ If some code uses a method which JSDOM (the DOM implementation used by Jest) has
141
141
In this case, mocking ` matchMedia ` in the test file should solve the issue:
142
142
143
143
``` js
144
- window .matchMedia = jest .fn ().mockImplementation (query => {
145
- return {
144
+ Object .defineProperty (window , ' matchMedia' , {
145
+ writable: true ,
146
+ value: jest .fn ().mockImplementation (query => ({
146
147
matches: false ,
147
148
media: query,
148
149
onchange: null ,
@@ -151,7 +152,7 @@ window.matchMedia = jest.fn().mockImplementation(query => {
151
152
addEventListener: jest .fn (),
152
153
removeEventListener: jest .fn (),
153
154
dispatchEvent: jest .fn (),
154
- };
155
+ })),
155
156
});
156
157
```
157
158
Original file line number Diff line number Diff line change @@ -142,8 +142,9 @@ If some code uses a method which JSDOM (the DOM implementation used by Jest) has
142
142
In this case, mocking ` matchMedia ` in the test file should solve the issue:
143
143
144
144
``` js
145
- window .matchMedia = jest .fn ().mockImplementation (query => {
146
- return {
145
+ Object .defineProperty (window , ' matchMedia' , {
146
+ writable: true ,
147
+ value: jest .fn ().mockImplementation (query => ({
147
148
matches: false ,
148
149
media: query,
149
150
onchange: null ,
@@ -152,7 +153,7 @@ window.matchMedia = jest.fn().mockImplementation(query => {
152
153
addEventListener: jest .fn (),
153
154
removeEventListener: jest .fn (),
154
155
dispatchEvent: jest .fn (),
155
- };
156
+ })),
156
157
});
157
158
```
158
159
You can’t perform that action at this time.
0 commit comments