Skip to content

Commit

Permalink
feat: integrate jest-matchmedia-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 28, 2021
1 parent 7c245bc commit ea9f370
Show file tree
Hide file tree
Showing 37 changed files with 323 additions and 726 deletions.
31 changes: 9 additions & 22 deletions plugins/addon-catalog/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
31 changes: 9 additions & 22 deletions plugins/addon-images/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
31 changes: 9 additions & 22 deletions plugins/addon-notes/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
31 changes: 9 additions & 22 deletions plugins/addon-stats/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
31 changes: 9 additions & 22 deletions plugins/axe-plugin/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
31 changes: 9 additions & 22 deletions plugins/figma-embed/tests/stories.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations, extractDocuments } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';

import { render, act } from '@testing-library/react';


let matchMedia: MatchMediaMock;

describe('component-controls generated', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../.config');
const config = loadConfigurations(configPath);
Expand Down
1 change: 1 addition & 0 deletions plugins/jest-snapshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.5.0",
"jest": "^26.4.2",
"jest-matchmedia-mock": "^1.1.0",
"react-dom": "^16.13.1",
"rc-util": "^5.0.7",
"react-test-renderer": "^16.13.1",
Expand Down
31 changes: 9 additions & 22 deletions plugins/jest-snapshots/templates/all-store.cjs.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
const path = require('path');
const MatchMediaMock = require('jest-matchmedia-mock').default;
{{=it.storeImports}}

{{=it.imports}}

let matchMedia;

describe('{{=it.name}}', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
{{=it.storeLoop}}

Expand Down
31 changes: 9 additions & 22 deletions plugins/jest-snapshots/templates/all-store.esm.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import * as path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
{{=it.storeImports}}

{{=it.imports}}

let matchMedia;

describe('{{=it.name}}', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
{{=it.storeLoop}}
});
31 changes: 9 additions & 22 deletions plugins/jest-snapshots/templates/all-store.ts.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
{{=it.storeImports}}

{{=it.imports}}

let matchMedia: MatchMediaMock;

describe('{{=it.name}}', () => {
beforeAll(async done => {
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
global.MutationObserver = class {
constructor() {}
disconnect() {}
observe() {}
takeRecords() {
return [];
}
};

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
done();
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
{{=it.storeLoop}}
});
Loading

0 comments on commit ea9f370

Please sign in to comment.