|
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' |
3 | 4 | import { firestore } from 'firebase'
|
| 5 | +import { defineComponent } from 'vue' |
4 | 6 |
|
5 |
| -const createLocalVue = () => { |
6 |
| - const newVue = Vue.extend() |
7 |
| - newVue.config = Vue.config |
8 |
| - return newVue |
9 |
| -} |
| 7 | +const component = defineComponent({ template: 'no' }) |
10 | 8 |
|
11 | 9 | describe('Firestore: plugin options', () => {
|
12 | 10 | 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 | + }, |
17 | 23 | })
|
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') |
20 | 26 | })
|
21 | 27 |
|
22 | 28 | it('calls custom serialize function with collection', async () => {
|
23 |
| - const LocalVue = createLocalVue() |
24 | 29 | const pluginOptions = {
|
25 | 30 | serialize: jest.fn(() => ({ foo: 'bar' })),
|
26 | 31 | }
|
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 | + ) |
28 | 43 |
|
29 | 44 | // @ts-ignore
|
30 | 45 | const items: firestore.CollectionReference = db.collection()
|
31 | 46 | await items.add({})
|
32 | 47 |
|
33 |
| - const vm = new LocalVue({ |
34 |
| - data: () => ({ items: [] }), |
35 |
| - }) |
36 |
| - |
37 |
| - await vm.$bind('items', items) |
| 48 | + await wrapper.vm.$bind('items', items) |
38 | 49 |
|
39 | 50 | expect(pluginOptions.serialize).toHaveBeenCalledTimes(1)
|
40 | 51 | expect(pluginOptions.serialize).toHaveBeenCalledWith(
|
41 | 52 | expect.objectContaining({ data: expect.any(Function) })
|
42 | 53 | )
|
43 |
| - expect(vm.items).toEqual([{ foo: 'bar' }]) |
| 54 | + expect(wrapper.vm.items).toEqual([{ foo: 'bar' }]) |
44 | 55 | })
|
45 | 56 |
|
46 |
| - it('can be ovrriden by local option', async () => { |
47 |
| - const LocalVue = createLocalVue() |
| 57 | + it('can be overridden by local option', async () => { |
48 | 58 | const pluginOptions = {
|
49 | 59 | serialize: jest.fn(() => ({ foo: 'bar' })),
|
50 | 60 | }
|
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 | + ) |
52 | 72 |
|
53 | 73 | // @ts-ignore
|
54 | 74 | const items: firestore.CollectionReference = db.collection()
|
55 | 75 | await items.add({})
|
56 | 76 |
|
57 |
| - const vm = new LocalVue({ |
58 |
| - data: () => ({ items: [] }), |
59 |
| - }) |
60 |
| - |
61 | 77 | const spy = jest.fn(() => ({ bar: 'bar' }))
|
62 | 78 |
|
63 |
| - await vm.$bind('items', items, { serialize: spy }) |
| 79 | + await wrapper.vm.$bind('items', items, { serialize: spy }) |
64 | 80 |
|
65 | 81 | expect(pluginOptions.serialize).not.toHaveBeenCalled()
|
66 | 82 | expect(spy).toHaveBeenCalledTimes(1)
|
67 | 83 | expect(spy).toHaveBeenCalledWith(
|
68 | 84 | expect.objectContaining({ data: expect.any(Function) })
|
69 | 85 | )
|
70 |
| - expect(vm.items).toEqual([{ bar: 'bar' }]) |
| 86 | + expect(wrapper.vm.items).toEqual([{ bar: 'bar' }]) |
71 | 87 | })
|
72 | 88 | })
|
0 commit comments