mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-05-17 05:09:39 +03:00
namespace support for actions (#24)
* namespace support for actions * renamed existing tests * added tests for store-actions with/without namespace * removed commit parts in action/dispatch tests * bugfixed failed test runs;
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ export default class {
|
||||
target = [msg.namespace || '', msg.mutation].filter((e) => !!e).join('/')
|
||||
} else if (msg.action) {
|
||||
method = 'dispatch'
|
||||
target = msg.action
|
||||
target = [msg.namespace || '', msg.action].filter((e) => !!e).join('/')
|
||||
}
|
||||
}
|
||||
this.store[method](target, msg)
|
||||
|
||||
@@ -4,12 +4,12 @@ import Observer from '@/Observer'
|
||||
|
||||
import { Server, WebSocket } from 'mock-socket'
|
||||
|
||||
describe ("Observer.js", () => {
|
||||
describe('Observer.js', () => {
|
||||
let observer, mockServer
|
||||
|
||||
let wsUrl = 'ws://localhost:8080'
|
||||
|
||||
it ('fires onopen event', (done) => {
|
||||
it('fires onopen event', (done) => {
|
||||
mockServer = new Server(wsUrl)
|
||||
mockServer.on('connection', ws => {
|
||||
ws.send('hi')
|
||||
@@ -24,7 +24,7 @@ describe ("Observer.js", () => {
|
||||
})
|
||||
|
||||
// TODO: DRY
|
||||
it ('passes a json event to the provided vuex store', (done) => {
|
||||
it('passes a json commit to the provided vuex store', (done) => {
|
||||
let expectedMsg = { mutation: 'setName', value: 'steve' }
|
||||
let mockStore = sinon.mock({ commit: () => {} })
|
||||
mockStore.expects('commit').withArgs('SOCKET_ONOPEN')
|
||||
@@ -49,8 +49,36 @@ describe ("Observer.js", () => {
|
||||
}, 100)
|
||||
})
|
||||
|
||||
// TODO: DRY
|
||||
it('passes a json action to the provided vuex store', (done) => {
|
||||
let expectedMsg = { action: 'setName', value: 'steve' }
|
||||
let mockStore = sinon.mock({
|
||||
commit: () => {},
|
||||
dispatch: () => {}
|
||||
})
|
||||
mockStore.expects('dispatch').withArgs(expectedMsg.action, expectedMsg)
|
||||
|
||||
mockServer = new Server(wsUrl)
|
||||
mockServer.on('connection', ws => {
|
||||
ws.send(JSON.stringify(expectedMsg))
|
||||
})
|
||||
|
||||
Vue.use(VueNativeSock, wsUrl)
|
||||
let vm = new Vue()
|
||||
observer = new Observer(wsUrl, {
|
||||
store: mockStore.object,
|
||||
format: 'json',
|
||||
websocket: new WebSocket(wsUrl)
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
mockStore.verify()
|
||||
mockServer.stop(done)
|
||||
}, 100)
|
||||
})
|
||||
|
||||
// TODO: DRY
|
||||
it ('passes a namespaced json event to the provided vuex store', (done) => {
|
||||
it('passes a namespaced json commit to the provided vuex store', (done) => {
|
||||
let expectedMsg = { namespace: 'users', mutation: 'setName', value: 'steve' }
|
||||
let mockStore = sinon.mock({ commit: () => {} })
|
||||
mockStore.expects('commit').withArgs('SOCKET_ONOPEN')
|
||||
@@ -75,5 +103,31 @@ describe ("Observer.js", () => {
|
||||
}, 100)
|
||||
})
|
||||
|
||||
})
|
||||
// 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({
|
||||
commit: () => {},
|
||||
dispatch: () => {}
|
||||
})
|
||||
mockStore.expects('dispatch').withArgs(expectedMsg.namespace + '/' + expectedMsg.action, expectedMsg)
|
||||
|
||||
mockServer = new Server(wsUrl)
|
||||
mockServer.on('connection', ws => {
|
||||
ws.send(JSON.stringify(expectedMsg))
|
||||
})
|
||||
|
||||
Vue.use(VueNativeSock, wsUrl)
|
||||
let vm = new Vue()
|
||||
observer = new Observer(wsUrl, {
|
||||
store: mockStore.object,
|
||||
format: 'json',
|
||||
websocket: new WebSocket(wsUrl)
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
mockStore.verify()
|
||||
mockServer.stop(done)
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user