Skip to content

Commit 23cd981

Browse files
committed
test: add firestore options
1 parent 9f036a1 commit 23cd981

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed
Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,88 @@
1-
import { firestorePlugin } from '../../src'
2-
import { db, Vue } from '@posva/vuefire-test-helpers'
1+
import { firestorePlugin } from '../../../src'
2+
import { db } from '../../src'
3+
import { mount } from '@vue/test-utils'
34
import { firestore } from 'firebase'
5+
import { defineComponent } from 'vue'
46

5-
const createLocalVue = () => {
6-
const newVue = Vue.extend()
7-
newVue.config = Vue.config
8-
return newVue
9-
}
7+
const component = defineComponent({ template: 'no' })
108

119
describe('Firestore: plugin options', () => {
1210
it('allows customizing $rtdbBind', () => {
13-
const LocalVue = createLocalVue()
14-
LocalVue.use(firestorePlugin, {
15-
bindName: '$myBind',
16-
unbindName: '$myUnbind',
11+
const wrapper = mount(component, {
12+
global: {
13+
plugins: [
14+
[
15+
firestorePlugin,
16+
{
17+
bindName: '$myBind',
18+
unbindName: '$myUnbind',
19+
},
20+
],
21+
],
22+
},
1723
})
18-
expect(typeof LocalVue.prototype.$myBind).toBe('function')
19-
expect(typeof LocalVue.prototype.$myUnbind).toBe('function')
24+
expect(typeof (wrapper.vm as any).$myBind).toBe('function')
25+
expect(typeof (wrapper.vm as any).$myUnbind).toBe('function')
2026
})
2127

2228
it('calls custom serialize function with collection', async () => {
23-
const LocalVue = createLocalVue()
2429
const pluginOptions = {
2530
serialize: jest.fn(() => ({ foo: 'bar' })),
2631
}
27-
LocalVue.use(firestorePlugin, pluginOptions)
32+
const wrapper = mount(
33+
{
34+
template: 'no',
35+
data: () => ({ items: [] }),
36+
},
37+
{
38+
global: {
39+
plugins: [[firestorePlugin, pluginOptions]],
40+
},
41+
}
42+
)
2843

2944
// @ts-ignore
3045
const items: firestore.CollectionReference = db.collection()
3146
await items.add({})
3247

33-
const vm = new LocalVue({
34-
data: () => ({ items: [] }),
35-
})
36-
37-
await vm.$bind('items', items)
48+
await wrapper.vm.$bind('items', items)
3849

3950
expect(pluginOptions.serialize).toHaveBeenCalledTimes(1)
4051
expect(pluginOptions.serialize).toHaveBeenCalledWith(
4152
expect.objectContaining({ data: expect.any(Function) })
4253
)
43-
expect(vm.items).toEqual([{ foo: 'bar' }])
54+
expect(wrapper.vm.items).toEqual([{ foo: 'bar' }])
4455
})
4556

46-
it('can be ovrriden by local option', async () => {
47-
const LocalVue = createLocalVue()
57+
it('can be overridden by local option', async () => {
4858
const pluginOptions = {
4959
serialize: jest.fn(() => ({ foo: 'bar' })),
5060
}
51-
LocalVue.use(firestorePlugin, pluginOptions)
61+
const wrapper = mount(
62+
{
63+
template: 'no',
64+
data: () => ({ items: [] }),
65+
},
66+
{
67+
global: {
68+
plugins: [[firestorePlugin, pluginOptions]],
69+
},
70+
}
71+
)
5272

5373
// @ts-ignore
5474
const items: firestore.CollectionReference = db.collection()
5575
await items.add({})
5676

57-
const vm = new LocalVue({
58-
data: () => ({ items: [] }),
59-
})
60-
6177
const spy = jest.fn(() => ({ bar: 'bar' }))
6278

63-
await vm.$bind('items', items, { serialize: spy })
79+
await wrapper.vm.$bind('items', items, { serialize: spy })
6480

6581
expect(pluginOptions.serialize).not.toHaveBeenCalled()
6682
expect(spy).toHaveBeenCalledTimes(1)
6783
expect(spy).toHaveBeenCalledWith(
6884
expect.objectContaining({ data: expect.any(Function) })
6985
)
70-
expect(vm.items).toEqual([{ bar: 'bar' }])
86+
expect(wrapper.vm.items).toEqual([{ bar: 'bar' }])
7187
})
7288
})

0 commit comments

Comments
 (0)