File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ import { fireEvent } from '@testing-library/react' ;
2+ import React from 'react' ;
3+ import { render } from '../../test-utils' ;
4+ import { TodoItem } from './TodoItem' ;
5+
6+ describe ( 'Todos components' , ( ) => {
7+ const todo = { id : "1" , title : "lorem ipsum" , completed : false } ;
8+
9+ it ( 'should render snapshot' , async ( ) => {
10+ const { container } = await render ( < TodoItem todo = { todo } onChange = { jest . fn ( ) } /> ) ;
11+
12+ expect ( container ) . toMatchSnapshot ( ) ;
13+ } ) ;
14+
15+ it ( 'should toggle status' , async ( ) => {
16+ const onChangeMock = jest . fn ( ) ;
17+ const { getByLabelText } = await render ( < TodoItem todo = { todo } onChange = { onChangeMock } /> ) ;
18+
19+ fireEvent . click ( getByLabelText ( todo . title ) ) ;
20+
21+ expect ( onChangeMock ) . toHaveBeenCalledWith ( { id : todo . id , completed : true } ) ;
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` Todos components should render snapshot 1` ] = `
4+ <div >
5+ <div
6+ class = " Todo__item"
7+ >
8+ <label
9+ for = " 1-checkbox"
10+ >
11+ lorem ipsum
12+ </label >
13+ <input
14+ id = " 1-checkbox"
15+ type = " checkbox"
16+ />
17+ </div >
18+ </div >
19+ ` ;
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import { cache } from '../apollo';
66
77const customRender = async (
88 childComponent : JSX . Element ,
9- options : MockedProviderProps
9+ options ? : MockedProviderProps
1010) : Promise < RenderResult > => {
11- const { mocks, resolvers = { } } = options ;
11+ const { mocks = [ ] , resolvers = { } } = options || { } ;
1212 const wrapper = render ( < MockedProvider
1313 mocks = { mocks }
1414 resolvers = { resolvers }
You can’t perform that action at this time.
0 commit comments