Skip to content

Commit

Permalink
fix: update tests and fix proptypes & invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofan2406 committed Mar 22, 2023
1 parent eb279d3 commit 611e8de
Show file tree
Hide file tree
Showing 109 changed files with 7,122 additions and 6,814 deletions.
17 changes: 14 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
{
"root": true,
"plugins": ["jest-dom"],
"extends": ["adslot", "plugin:jest-dom/recommended", "plugin:import/typescript"],
"extends": ["adslot", "plugin:import/typescript"],
"settings": {
"lodash": {
"version": 4
},
"import/resolver": {
"alias": {
"map": [["testing", "./config/testing"]]
}
}
},
"rules": {
"no-console": ["error", { "allow": ["warn", "error"] }],
"@typescript-eslint/no-explicit-any": "off"
}
},

"overrides": [
{
"files": ["**/?(*.)+(spec|test).js?(x)"],
"extends": ["plugin:jest-dom/recommended", "plugin:testing-library/react"]
}
]
}
6 changes: 3 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
coverage:
round: down
precision: 2
range: 98...100
range: 95...100
ignore:
- 'src/components/**/*.spec.*'
- 'src/components/**/mocks.*'
- 'src/**/*.spec.*'
- 'src/**/mocks.*'
status:
project:
default:
Expand Down
56 changes: 46 additions & 10 deletions config/testSetup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';

window.matchMedia = jest.fn().mockImplementation((query) => {
return {
// for slick-carousel, date picker
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
};
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}),
});

// for RichTextEditor
Object.defineProperty(window, 'scrollTo', {
writable: true,
value: jest.fn(),
});

Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', {
writable: true,
value: jest.fn(),
});

// for Paragraph
Object.defineProperty(window, 'ResizeObserver', {
writable: true,
value: class ResizeObserver {
observe = jest.fn();
unobserve = jest.fn();
disconnect = jest.fn();
},
});

// for cropperjs
beforeEach(() => {
jest.spyOn(XMLHttpRequest.prototype, 'open').mockReturnValue();
jest.spyOn(XMLHttpRequest.prototype, 'send').mockReturnValue();
});

Object.defineProperty(window, 'scrollTo', { value: () => {}, writable: true });
window.ResizeObserver = class ResizeObserver {
observe = jest.fn();
unobserve = jest.fn();
disconnect = jest.fn();
};
// auto mock invariant to avoid console error
jest.mock('../src/invariant', () => {
const originalModule = jest.requireActual('../src/invariant');

return {
__esModule: true,
...originalModule,
default: jest.fn(),
};
});
Loading

0 comments on commit 611e8de

Please sign in to comment.