File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import { mount } from "enzyme" ;
3
+ import Root from "Root" ;
4
+ import App from "components/App" ;
5
+ import moxios from "moxios" ;
6
+
7
+ moxios . install ( ) ;
8
+ moxios . stubRequest ( 'https://json-server-comment.herokuapp.com/comments' , {
9
+ status : 200 ,
10
+ response : [
11
+ { name : 'Fetched #1' } ,
12
+ { name : 'Fetched #2' } ,
13
+ { name : 'Fetched #3' }
14
+ ]
15
+ } )
16
+
17
+ afterEach ( ( ) => {
18
+ moxios . uninstall ( ) ;
19
+ } )
20
+
21
+ it ( 'can fetch a list of comments and display them' , ( done ) => {
22
+ const wrapped = mount (
23
+ < Root >
24
+ < App />
25
+ </ Root >
26
+ )
27
+ wrapped . find ( '.fetch-comments' ) . simulate ( 'click' ) ;
28
+ moxios . wait ( ( ) => {
29
+ wrapped . update ( ) ;
30
+ expect ( wrapped . find ( 'li' ) . length ) . toEqual ( 3 ) ;
31
+ done ( ) ;
32
+ wrapped . unmount ( ) ;
33
+ } )
34
+ } )
You can’t perform that action at this time.
0 commit comments