Skip to content

Commit 9d9cbf8

Browse files
authored
Merge pull request #107 from World-of-Code/f/testLocation
added store location test
2 parents 7433dff + 11da42e commit 9d9cbf8

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
})

server/api/locations/locations.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Location routes', () => {
3232
return Location.findById(createLocations.id)
3333
})
3434
.then(foundLocation => {
35-
console.log("FOUND", foundLocation)
35+
// console.log("FOUND", foundLocation)
3636
expect(foundLocation.url).to.be.equal('https://www.youtube.com/watch?v=BMUiFMZr7vk');
3737
})
3838
})

0 commit comments

Comments
 (0)