test('clicking the delete button of a todo removes the todo', () => { const { queryByText, getByText, getByPlaceholderText, getByTestId, container } = render(<App />); // make sure 'Ride bike' is in the DOM expect(queryByText('Ride bike')).not.toBeNull(); // click delete button on 'Ride bike' const deleteBtn = getByText('Ride bike').parentElement.querySelector('button'); Simulate.click(deleteBtn); // make sure 'Ride bike' is not in the DOM expect(queryByText('Ride bike')).toBeNull(); });
test('get weather', async () => { const { getByText, queryByText, container } = render(<Weather location="charleston" />) await wait(() => expect(queryByText(/loading/i)).not.toBeInTheDocument()) expect(getByText(/raining/)).toBeInTheDocument() })
describe('<ConnectedLanguageProvider />', () => { let store; beforeAll(() => { store = configureStore({}, browserHistory); }); it('should render the default language messages', () => { const { queryByText } = render( <Provider store={store}> <ConnectedLanguageProvider messages={translationMessages}> <FormattedMessage {...messages.someMessage} /> </ConnectedLanguageProvider> </Provider>, ); expect(queryByText(messages.someMessage.defaultMessage)).not.toBeNull(); }); });
describe('components', function() { describe('UserMenu', function() { it('should render sign in link w/ no user', function() { // render component to the page const { getByText, queryByText } = render(<UserMenu />); expect(getByText('Sign In')).toBeInTheDocument(); expect(queryByText('Tom Wayson')).toBeNull(); }); it('should render full name w/ a user', function() { const mockUser = { fullName: 'Tom Wayson' }; // render component to the page const { getByText, queryByText } = render( <UserMenu currentUser={mockUser} /> ); expect(queryByText('Sign In')).toBeNull(); expect(getByText('Tom Wayson')).toBeInTheDocument(); }); }); });
describe("CommentForm", () => { test("has a text area, text input and submit button", () => { const {getByPlaceholderText, getByLabelText, getByText} = render(<CommentForm />); expect(getByPlaceholderText("Write something...")).toBeInTheDocument() expect(getByLabelText("Your Name")).toBeInTheDocument() expect(getByText("Submit")).toBeInTheDocument() }); test("submit button is disabled on load", () => { const {getByText} = render(<CommentForm />); expect(getByText("Submit")).toHaveAttribute("disabled") }); test("submit button is enabled after fields are filled in", () => { const sampleComment = "Some comment" const sampleAuthor = "Mary" const {getByPlaceholderText, getByLabelText, queryByText} = render(<CommentForm />); const textArea = getByPlaceholderText("Write something...") const input = getByLabelText("Your Name") fireEvent.change(textArea, { target: { value: sampleComment } }) fireEvent.change(input, { target: { value: sampleAuthor } }) expect(queryByText("Submit")).not.toHaveAttribute("disabled") }); });
describe('<ConnectedLanguageProvider />', () => { let store; beforeAll(() => { store = configureStore({}, browserHistory); }); it('should render the default language messages', () => { const { queryByText } = render( <Provider store={store}> <ConnectedLanguageProvider messages={translationMessages}> <FormattedMessage {...messages.someMessage} /> </ConnectedLanguageProvider> </Provider>, ); expect(queryByText(messages.someMessage.defaultMessage)).not.toBeNull(); }); });