Skip to content
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

Setting up test suite and adding an example test #15

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion themes/10up-theme/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"extends": ["@10up/eslint-config/wordpress"]
"settings": {
"jest": {
"version": 25,
"react": 17
}
},
"extends": ["@10up/eslint-config/wordpress", "@10up/eslint-config/jest"]
}
6 changes: 6 additions & 0 deletions themes/10up-theme/__mocks__/@wordpress/block-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable react/prop-types */
const RichText = ({ onChange }) => <textarea onChange={onChange} />;

module.exports = {
RichText,
};
3 changes: 3 additions & 0 deletions themes/10up-theme/__mocks__/@wordpress/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
__: jest.fn((text) => text),
};
3 changes: 3 additions & 0 deletions themes/10up-theme/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@10up/babel-preset-default', { wordpress: true }]],
};
23 changes: 23 additions & 0 deletions themes/10up-theme/includes/blocks/example-block/__tests__/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Edit from '../edit';

describe('example block', () => {
test('edit component works', () => {
const setAttributes = jest.fn();
const { container } = render(
<Edit setAttributes={setAttributes} attributes={{ currentTitle: 'test' }} />,
);

expect(container).toMatchInlineSnapshot(`
<div>
<div>
<textarea />
</div>
</div>
`);

userEvent.type(screen.getByRole('textbox'), 'my value');
expect(setAttributes).toHaveBeenCalled();
});
});
4 changes: 4 additions & 0 deletions themes/10up-theme/jest-unit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: '@wordpress/jest-preset-default',
setupFilesAfterEnv: ['./setupTests.js'],
};
1,123 changes: 816 additions & 307 deletions themes/10up-theme/package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions themes/10up-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
"format-js": "10up-scripts format-js",
"lint-js": "10up-scripts lint-js",
"lint-style": "10up-scripts lint-style",
"test": "10up-scripts test-unit-jest"
"test": "10up-scripts test-unit-jest",
"test-watch": "10up-scripts test-unit-jest --watch"
},
"engines": {
"node": ">=12.0.0"
},
"devDependencies": {
"@10up/scripts": "^1.1.1"
"@10up/scripts": "^1.1.3",
"@testing-library/dom": "^7.29.6",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.7.3"
},
"dependencies": {
"normalize.css": "^8.0.1",
Expand Down
2 changes: 2 additions & 0 deletions themes/10up-theme/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';