File tree Expand file tree Collapse file tree 4 files changed +68
-8
lines changed Expand file tree Collapse file tree 4 files changed +68
-8
lines changed Original file line number Diff line number Diff line change 1+ import { shallow } from 'enzyme' ;
12import React from 'react' ;
2- import { render } from '@testing-library/react' ;
33import App from './App' ;
4-
5- test ( 'renders learn react link' , ( ) => {
6- const { getByText } = render ( < App /> ) ;
7- const linkElement = getByText ( / l e a r n r e a c t / i ) ;
8- expect ( linkElement ) . toBeInTheDocument ( ) ;
4+ import Adapter from 'enzyme-adapter-react-16' ;
5+ import { configure } from 'enzyme' ;
6+ configure ( { adapter : new Adapter ( ) } ) ;
7+ it ( "renders without crashing" , ( ) => {
8+ shallow ( < App /> ) ;
99} ) ;
10+
11+ it ( "renders Account header" , ( ) => {
12+ const wrapper = shallow ( < App /> ) ;
13+ const welcome = < p > </ p > ;
14+ expect ( wrapper . contains ( welcome ) ) . toEqual ( false ) ;
15+ } ) ;
Original file line number Diff line number Diff line change 1- class MockApi {
1+ export default class MockApi {
22 constructor ( defaultUsers = [ ] , latency = 500 ) {
33 this . defaultUsers = defaultUsers ;
44 this . latency = latency ;
@@ -69,4 +69,3 @@ class MockApi {
6969 }
7070}
7171
72- export default MockApi ;
Original file line number Diff line number Diff line change 1+ import Adapter from 'enzyme-adapter-react-16' ;
2+ import { configure , shallow } from 'enzyme' ;
3+ import { MockApi } from './MockApi' ;
4+ configure ( { adapter : new Adapter ( ) } ) ;
5+
6+ jest . mock ( './MockApi' , ( ) => {
7+ // Works and lets you check for constructor calls:
8+ return {
9+ MockApi : jest . fn ( ) . mockImplementation ( ( ) => {
10+ return {
11+ getAllUSers : ( ) => [ ] ,
12+ setUsers : ( ) => undefined ,
13+ } ;
14+ } ) ,
15+ } ;
16+ } ) ;
17+
18+ beforeEach ( ( ) => {
19+ MockApi . mockClear ( ) ;
20+ } ) ;
21+
22+
23+
24+ it ( 'requires be an array to get all users method result' , ( ) => {
25+ const mockApi = new MockApi ( ) ;
26+ expect ( mockApi . getAllUSers ( ) ) . toEqual ( [ ] ) ;
27+ } ) ;
28+
29+ it ( 'requires set users as an array' , ( ) => {
30+ const mockApi = new MockApi ( ) ;
31+ expect ( mockApi . setUsers ( ) ) . toEqual ( undefined ) ;
32+ } ) ;
33+
Original file line number Diff line number Diff line change 1+ import { mount , shallow } from 'enzyme' ;
2+ import React from 'react' ;
3+ import Adapter from 'enzyme-adapter-react-16' ;
4+ import { configure } from 'enzyme' ;
5+ import Page from './Page' ;
6+ configure ( { adapter : new Adapter ( ) } ) ;
7+
8+ it ( 'renders without crashing' , ( ) => {
9+ shallow ( < Page > < div > </ div > </ Page > )
10+ } ) ;
11+
12+ it ( 'requires render with children' , ( ) => {
13+ const children = < p > </ p > ;
14+ const wrapper = shallow ( < Page > { children } </ Page > ) ;
15+ expect ( wrapper . contains ( children ) ) . toEqual ( true ) ;
16+ } ) ;
17+
18+ it ( 'requires contain children props' , ( ) => {
19+ const children = < p > this is children</ p > ;
20+ const wrapper = mount ( < Page > { children } </ Page > ) ;
21+ expect ( wrapper . props ( ) . children ) . toEqual ( children ) ;
22+ } ) ;
You can’t perform that action at this time.
0 commit comments