Last active
October 9, 2018 00:34
-
-
Save rcdexta/66aea4f42a5eac245d2a52612cb479d2 to your computer and use it in GitHub Desktop.
TodoListItem.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {render, fireEvent} from 'react-testing-library' | |
import TodoListItem from '../TodoListItem' | |
test('TodoListItem should render passed props as content body and respond to callback props', () => { | |
const markTodoDone = jest.fn() | |
const removeItem = jest.fn() | |
const item = {index: 3, value: "Fill Gas", done: false} | |
let itemIndex = 5 | |
const {getByTestId} = render(<TodoListItem item={item} index={itemIndex} | |
markTodoDone={markTodoDone} | |
removeItem={removeItem}/>) | |
expect(getByTestId('todoItem3').textContent).toBe('Fill Gas') | |
fireEvent.click(getByTestId('markAsCompleted')) | |
expect(markTodoDone).toBeCalledWith(itemIndex) | |
expect(markTodoDone).toHaveBeenCalledTimes(1) | |
fireEvent.click(getByTestId('markAsDeleted')) | |
expect(removeItem).toBeCalledWith(itemIndex) | |
expect(removeItem).toHaveBeenCalledTimes(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment