-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Tests: Improve configuration and mocking strategy #8188
Changes from 3 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const apiFetch = jest.fn( () => { | ||
return apiFetch.mockReturnValue; | ||
} ); | ||
apiFetch.mockReturnValue = 'mock this value by overriding apiFetch.mockReturnValue'; | ||
|
||
export default apiFetch; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import { mount } from 'enzyme'; | |
*/ | ||
import MoreMenu from '../index'; | ||
|
||
jest.mock( '../../../../../packages/components/src/button' ); | ||
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. That is a nigh-unusable import path? I know there's discussion around just using absolute paths everywhere (I brought it up in a chat and should really file an issue... so: #8190). But this should be absolute if possible. It's really unusable to try to figure out what this is importing. 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. Agreed, it took me some time to build them properly 😅 In the first place, I want to get rid of those mocks completely with #7005 which will sort of resolve this issue :D |
||
|
||
describe( 'MoreMenu', () => { | ||
it( 'should match snapshot', () => { | ||
const wrapper = mount( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,8 +144,8 @@ | |
"scripts": { | ||
"prebuild": "npm run check-engines", | ||
"clean:packages": "rimraf ./packages/*/build ./packages/*/build-module ./packages/*/build-style", | ||
"prebuild:packages": "npm run clean:packages && lerna run build && cross-env INCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,postcss-themes SKIP_JSX_PRAGMA_TRANSFORM=1 node ./bin/packages/build.js", | ||
"build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,postcss-themes node ./bin/packages/build.js", | ||
"prebuild:packages": "npm run clean:packages && lerna run build && cross-env INCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,postcss-themes,jest-console SKIP_JSX_PRAGMA_TRANSFORM=1 node ./bin/packages/build.js", | ||
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. Why are we including these other packages in the prebuild? 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.
|
||
"build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,jest-console,postcss-themes node ./bin/packages/build.js", | ||
"build": "npm run build:packages && cross-env NODE_ENV=production webpack", | ||
"check-engines": "check-node-version --package", | ||
"ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\"", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// [TEMPORARY]: Button uses React.forwardRef, added in [email protected] but not yet | ||
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. Thanks for the docs! 👍 |
||
// supported by Enzyme as of [email protected] . This mock unwraps | ||
// the ref forwarding, so any tests relying on this behavior will fail. | ||
// | ||
// See: https://github.com/airbnb/enzyme/issues/1604 | ||
// See: https://github.com/airbnb/enzyme/pull/1592/files | ||
|
||
const { Component } = require( 'react' ); | ||
const { Button: RawButton } = require.requireActual( '../index' ); | ||
|
||
class Button extends Component { | ||
render() { | ||
return RawButton( this.props ); | ||
} | ||
} | ||
|
||
export default Button; |
This file was deleted.
This file was deleted.
This file was deleted.
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.
Maybe make this a full sentence?
'Mock this value by overriding apiFetch.mockReturnValue.'
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.
I copied it over - can tweak 👍