-
Notifications
You must be signed in to change notification settings - Fork 667
Use jsdom env. for testing and plugin-stats #1871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| window.matchMedia = () => ({matches: true}); | ||
| window.matchMedia = () => ({ matches: true }); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,15 +38,15 @@ describe('BaseNode', () => { | |
| .find('.odc-base-node__bg') | ||
| .first() | ||
| .props().filter, | ||
| ).toBe('url(blank#BaseNodeDropShadowFilterId)'); | ||
| ).toBe('url(/#BaseNodeDropShadowFilterId)'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are due to setting |
||
|
|
||
| wrapper.setState({ hover: true }); | ||
| expect( | ||
| wrapper | ||
| .find('.odc-base-node__bg') | ||
| .first() | ||
| .props().filter, | ||
| ).toBe('url(blank#BaseNodeDropShadowFilterId--hover)'); | ||
| ).toBe('url(/#BaseNodeDropShadowFilterId--hover)'); | ||
| }); | ||
|
|
||
| it('should show long labels when selected', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ export function getDefaultPerspective() { | |
| activePerspective = defaultPerspective.properties.id; | ||
| } | ||
| } | ||
| return activePerspective; | ||
| return activePerspective || undefined; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to coerce the expectation (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is something breaking without this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Without this, expect(getDefaultPerspective()).toBeUndefined();(expected
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bad test. |
||
| } | ||
|
|
||
| export default (state: UIState, action: UIAction): UIState => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* eslint-env node */ | ||
|
|
||
| // https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md | ||
|
|
||
| import { JSDOM } from 'jsdom'; | ||
|
|
||
| const jsdom = new JSDOM('<!doctype html><html><body></body></html>'); | ||
| const { window } = jsdom; | ||
|
|
||
| function copyProps(src, target) { | ||
| Object.defineProperties(target, { | ||
| ...Object.getOwnPropertyDescriptors(src), | ||
| ...Object.getOwnPropertyDescriptors(target), | ||
| }); | ||
| } | ||
|
|
||
| global.window = window; | ||
| global.document = window.document; | ||
| global.navigator = { | ||
| userAgent: 'node.js', | ||
| }; | ||
| global.requestAnimationFrame = (callback) => setTimeout(callback, 0); | ||
| global.cancelAnimationFrame = (id) => { | ||
| clearTimeout(id); | ||
| }; | ||
|
|
||
| copyProps(window, global); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: these changes are made so that mock
localStorageis as close to production as possible in terms of its API.For example, in case of
getItemmethod:https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should only return null if the key doesn't exist. If the value is an empty string, this will incorrectly return
null.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I've missed that. Will fix that in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1925