2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-19 22:30:34 +03:00

Fix custom mutations feature + test

This commit is contained in:
sharkykh
2018-09-12 19:13:09 +03:00
parent 05b80e9426
commit 967f58f317
4 changed files with 85 additions and 24 deletions
+32 -2
View File
@@ -63,7 +63,7 @@ describe('Observer.js', () => {
}, 100)
})
// TODO: DRY
// TODO: DRY
it('passes a json action to the provided vuex store', (done) => {
let expectedMsg = { action: 'setName', value: 'steve' }
let mockStore = sinon.mock({
@@ -117,7 +117,7 @@ describe('Observer.js', () => {
}, 100)
})
// TODO: DRY
// TODO: DRY
it('passes a namespaced json action to the provided vuex store', (done) => {
let expectedMsg = { namespace: 'users', action: 'setName', value: 'steve' }
let mockStore = sinon.mock({
@@ -145,6 +145,36 @@ describe('Observer.js', () => {
}, 100)
})
// TODO: DRY
it('passes a custom commit name to the provided vuex store', (done) => {
let expectedMsg = 'hello world'
let mutations = {
SOCKET_ONOPEN: '✅ Socket connected',
SOCKET_ONMESSAGE: 'Websocket message received'
}
let mockStore = sinon.mock({ commit: () => {} })
mockStore.expects('commit').withArgs(mutations.SOCKET_ONOPEN)
mockStore.expects('commit').withArgs(mutations.SOCKET_ONMESSAGE)
mockServer = new Server(wsUrl)
mockServer.on('connection', ws => {
ws.send(expectedMsg)
})
Vue.use(VueNativeSock, wsUrl)
let vm = new Vue()
observer = new Observer(wsUrl, {
store: mockStore.object,
mutations,
websocket: new WebSocket(wsUrl)
})
setTimeout(() => {
mockStore.verify()
mockServer.stop(done)
}, 100)
})
describe('reconnection feature', () => {
let observer, mockServer, vm, mockStore
let wsUrl = 'ws://localhost:8080'