Skip to content

Enforce best practices for testing #2357

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
"rules": {
"import/no-extraneous-dependencies": "off"
}
},
{
"files": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
"extends": [
"plugin:jest-dom/recommended",
"plugin:testing-library/react"
],
"rules": {
"testing-library/render-result-naming-convention": "off"
}
}
]
}
15 changes: 5 additions & 10 deletions client/index.integration.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rest } from 'msw';
import React from 'react';
import Routing from './routes';

import { reduxRender, act, waitFor, screen, within } from './test-utils';
import { reduxRender, waitFor, screen, within } from './test-utils';
import configureStore from './store';
import * as Actions from './modules/User/actions';
import { userResponse } from './testData/testServerResponses';
Expand Down Expand Up @@ -60,9 +60,8 @@ describe('index.jsx integration', () => {
const spy = jest.spyOn(Actions, 'getUser');

beforeEach(async () => {
act(() => {
subject();
});
// eslint-disable-next-line testing-library/no-render-in-setup
subject();

await waitFor(() => expect(spy).toHaveBeenCalledTimes(1));
});
Expand Down Expand Up @@ -151,18 +150,14 @@ describe('index.jsx integration', () => {
// });
// const preview = screen.getByRole('main', { name: /sketch preview/i });
// expect(preview.getAttribute('srcdoc')).toBeFalsy();
// act(() => {
// fireEvent.click(playButton);
// });
// fireEvent.click(playButton);

// expect(preview.getAttribute('srcdoc')).toBeTruthy();

// const stopButton = screen.getByRole('button', {
// name: /stop sketch/i
// });
// act(() => {
// fireEvent.click(stopButton);
// });
// fireEvent.click(stopButton);
// expect(preview.getAttribute('srcdoc')).toMatch(/(^|")\s*($|")/);
// });
});
5 changes: 1 addition & 4 deletions client/modules/IDE/components/Editor.unit.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { act } from 'react-dom/test-utils';
import Editor from './Editor';
import { reduxRender } from '../../../test-utils';
import { initialTestState } from '../../../testData/testReduxStore';
Expand All @@ -21,8 +20,6 @@ describe('<Editor />', () => {
});

it('renders successfully', () => {
act(() => {
subject();
});
subject();
});
});
15 changes: 4 additions & 11 deletions client/modules/IDE/components/FileNode.unit.test.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import React from 'react';

import {
fireEvent,
render,
screen,
waitFor,
within
} from '../../../test-utils';
import { fireEvent, render, screen, waitFor } from '../../../test-utils';
import { FileNode } from './FileNode';

describe('<FileNode />', () => {
const changeName = (newFileName) => {
const renameButton = screen.getByText(/Rename/i);
fireEvent.click(renameButton);

const input = screen.getByTestId('input');
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: newFileName } });
fireEvent.blur(input);
};

const expectFileNameToBe = async (expectedName) => {
const name = screen.getByTestId('file-name');
await waitFor(() => within(name).queryByText(expectedName));
const name = await screen.findByRole('button', { name: expectedName });
expect(name).toBeInTheDocument();
};

const renderFileNode = (fileType, extraProps = {}) => {
Expand Down
Loading