Skip to content

Commit 9c58465

Browse files
committed
test: make pending hot-reload test pass
1 parent 3d9919a commit 9c58465

File tree

5 files changed

+344
-59
lines changed

5 files changed

+344
-59
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"express": "^4.14.1",
5959
"jasmine": "2.8.0",
6060
"jasmine-core": "2.8.0",
61+
"jsdom": "^16.2.2",
6162
"nightwatch": "^1.3.1",
6263
"nightwatch-helpers": "^1.2.0",
6364
"rollup": "^1.1.0",

test/unit/hot-reload.spec.js

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// import { createApp, nextTick } from 'vue'
1+
import { nextTick } from 'vue'
2+
import { mount } from './support/helpers'
23
import Vuex from '../../dist/vuex.common.js'
34

45
const TEST = 'TEST'
5-
// const isSSR = process.env.VUE_ENV === 'server'
6+
const isSSR = process.env.VUE_ENV === 'server'
67

78
describe('Hot Reload', () => {
89
it('mutations', function () {
@@ -233,67 +234,62 @@ describe('Hot Reload', () => {
233234
expect(store.state.list.join()).toBe('1,2,3,2,4,5')
234235
})
235236

236-
// Skipping for now due to unkown error;
237-
// TypeError: Cannot read property 'createComment' of null
238-
//
239-
// it('getters', done => {
240-
// const store = new Vuex.Store({
241-
// state: {
242-
// count: 0
243-
// },
244-
// mutations: {
245-
// inc: state => state.count++
246-
// },
247-
// getters: {
248-
// count: state => state.count
249-
// },
250-
// actions: {
251-
// check ({ getters }, value) {
252-
// expect(getters.count).toBe(value)
253-
// }
254-
// }
255-
// })
237+
it('getters', done => {
238+
const store = new Vuex.Store({
239+
state: {
240+
count: 0
241+
},
242+
mutations: {
243+
inc: state => state.count++
244+
},
245+
getters: {
246+
count: state => state.count
247+
},
248+
actions: {
249+
check ({ getters }, value) {
250+
expect(getters.count).toBe(value)
251+
}
252+
}
253+
})
256254

257-
// const spy = jasmine.createSpy()
258-
// const app = createApp({
259-
// computed: {
260-
// a: () => store.getters.count
261-
// },
262-
// watch: {
263-
// a: spy
264-
// },
265-
// render () {}
266-
// })
267-
// app.use(Vuex, store)
268-
// const vm = app.mount({ appendChild: () => {} })
255+
const spy = jasmine.createSpy()
269256

270-
// expect(vm.a).toBe(0)
271-
// store.dispatch('check', 0)
257+
const vm = mount(store, {
258+
computed: {
259+
a: () => store.getters.count
260+
},
261+
watch: {
262+
a: spy
263+
}
264+
})
272265

273-
// store.commit('inc')
266+
expect(vm.a).toBe(0)
267+
store.dispatch('check', 0)
274268

275-
// expect(vm.a).toBe(1)
276-
// store.dispatch('check', 1)
269+
store.commit('inc')
277270

278-
// // update getters
279-
// store.hotUpdate({
280-
// getters: {
281-
// count: state => state.count * 10
282-
// }
283-
// })
271+
expect(vm.a).toBe(1)
272+
store.dispatch('check', 1)
284273

285-
// expect(vm.a).toBe(10)
286-
// store.dispatch('check', 10)
274+
// update getters
275+
store.hotUpdate({
276+
getters: {
277+
count: state => state.count * 10
278+
}
279+
})
280+
281+
expect(vm.a).toBe(10)
282+
store.dispatch('check', 10)
287283

288-
// if (isSSR) {
289-
// done()
290-
// } else {
291-
// nextTick(() => {
292-
// expect(spy).toHaveBeenCalled()
293-
// done()
294-
// })
295-
// }
296-
// })
284+
if (isSSR) {
285+
done()
286+
} else {
287+
nextTick(() => {
288+
expect(spy).toHaveBeenCalled()
289+
done()
290+
})
291+
}
292+
})
297293

298294
it('provide warning if a new module is given', () => {
299295
const store = new Vuex.Store({})

test/unit/setup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
import 'babel-polyfill'
2+
import { JSDOM } from 'jsdom'
3+
4+
const dom = new JSDOM('<html><body></body></html>')
5+
6+
global.document = dom.window.document
7+
global.window = dom.window
8+
global.navigator = dom.window.navigator

test/unit/support/helpers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createApp } from 'vue'
2+
3+
export function mount (store, component) {
4+
const el = createElement()
5+
6+
component.render = () => {}
7+
8+
const app = createApp(component)
9+
10+
app.use(store)
11+
12+
return app.mount(el)
13+
}
14+
15+
function createElement () {
16+
const el = document.createElement('div')
17+
18+
document.body.appendChild(el)
19+
20+
return el
21+
}

0 commit comments

Comments
 (0)