Skip to content

Instantly share code, notes, and snippets.

@livando
Last active July 20, 2020 15:46
Show Gist options
  • Save livando/6bac7b57a4e8e098469511a43dd0ddf5 to your computer and use it in GitHub Desktop.
Save livando/6bac7b57a4e8e098469511a43dd0ddf5 to your computer and use it in GitHub Desktop.
Basic React Test
// https://reactjs.org/docs/testing-recipes.html
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import NewComment from '../NewComment';
let div = document.createElement('div');
beforeEach(() => {
div = document.createElement('div');
document.body.appendChild(div);
});
afterEach(() => {
ReactDOM.unmountComponentAtNode(div);
div.remove();
div = null;
});
describe('Popup for initial comment', () => {
it('has a link to post', () => {
act(() => {
ReactDOM.render(<NewComment />, div);
});
const firstLink = div.querySelector('a');
expect(firstLink.text).toEqual('post');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment