File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import { expect } from 'chai'
3
+ import { registerLocation } from './index.js'
4
+ import axios from 'axios'
5
+ import MockAdapter from 'axios-mock-adapter'
6
+ import configureMockStore from 'redux-mock-store'
7
+ import thunkMiddleware from 'redux-thunk'
8
+
9
+ const middlewares = [ thunkMiddleware ]
10
+ const mockStore = configureMockStore ( middlewares )
11
+
12
+ describe ( 'thunk creators' , ( ) => {
13
+ let store
14
+ let mockAxios
15
+
16
+ const initialState = { locations : [ ] , location : { } }
17
+
18
+ beforeEach ( ( ) => {
19
+ mockAxios = new MockAdapter ( axios )
20
+ store = mockStore ( initialState )
21
+ } )
22
+
23
+ afterEach ( ( ) => {
24
+ mockAxios . restore ( )
25
+ store . clearActions ( )
26
+ } )
27
+
28
+
29
+ describe ( 'registerLocation' , ( ) => {
30
+ it ( 'eventually dispatches the registerLocation action' , ( ) => {
31
+ const fakeLocation = { id : 4 , url : 'https://www.youtube.com/' }
32
+ mockAxios . onPost ( 'https://code-mode.herokuapp.com/api/locations/register' ) . replyOnce ( 201 , fakeLocation )
33
+ return store . dispatch ( registerLocation ( fakeLocation ) )
34
+ . then ( ( ) => {
35
+ const actions = store . getActions ( )
36
+ expect ( actions [ 0 ] . type ) . to . be . equal ( 'CREATE_LOCATION' )
37
+ expect ( actions [ 0 ] . location ) . to . be . deep . equal ( fakeLocation )
38
+
39
+ } )
40
+ } )
41
+ } )
42
+
43
+ } )
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ describe('Location routes', () => {
32
32
return Location . findById ( createLocations . id )
33
33
} )
34
34
. then ( foundLocation => {
35
- console . log ( "FOUND" , foundLocation )
35
+ // console.log("FOUND", foundLocation)
36
36
expect ( foundLocation . url ) . to . be . equal ( 'https://www.youtube.com/watch?v=BMUiFMZr7vk' ) ;
37
37
} )
38
38
} )
You can’t perform that action at this time.
0 commit comments