Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Last active October 9, 2018 00:34
Show Gist options
  • Save rcdexta/66aea4f42a5eac245d2a52612cb479d2 to your computer and use it in GitHub Desktop.
Save rcdexta/66aea4f42a5eac245d2a52612cb479d2 to your computer and use it in GitHub Desktop.
TodoListItem.test
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