Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 3a8ac26

Browse files
committed
test: fix failing tests
1 parent bf55fb9 commit 3a8ac26

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

__tests__/vuefire/rtdb/merging.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ function createMixins() {
4545
return { mWithFn, mWithObjA, mWithObjB, docs }
4646
}
4747

48-
const global = {
49-
plugins: [rtdbPlugin],
48+
const globalMountingOptions = {
49+
global: {
50+
plugins: [rtdbPlugin],
51+
},
5052
}
5153

5254
describe('RTDB: merging', () => {
@@ -58,7 +60,7 @@ describe('RTDB: merging', () => {
5860
// @ts-ignore
5961
mixins: [mWithObjA, mWithObjB],
6062
},
61-
{ global }
63+
globalMountingOptions
6264
)
6365
expect(Object.keys(vm.$firebaseRefs)).toEqual(['a', 'b', 'c'])
6466
expect(vm.$firebaseRefs).toEqual({
@@ -75,7 +77,7 @@ describe('RTDB: merging', () => {
7577
template: 'no',
7678
mixins: [mWithFn],
7779
},
78-
{ global }
80+
globalMountingOptions
7981
)
8082
expect(vm.$firebaseRefs).toEqual({
8183
a: docs[4],
@@ -91,7 +93,7 @@ describe('RTDB: merging', () => {
9193
// @ts-ignore
9294
mixins: [mWithObjA, mWithObjB, mWithFn],
9395
},
94-
{ global }
96+
globalMountingOptions
9597
)
9698
expect(vm.$firebaseRefs).toEqual({
9799
a: docs[4],

__tests__/vuefire/rtdb/options.spec.ts

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
import { rtdbPlugin } from '../../src'
2-
import { Vue, MockFirebase } from '@posva/vuefire-test-helpers'
3-
4-
const createLocalVue = () => {
5-
const newVue = Vue.extend()
6-
newVue.config = Vue.config
7-
return newVue
8-
}
1+
import { mount } from '@vue/test-utils'
2+
import { rtdbPlugin } from '../../../src'
3+
import { MockFirebase } from '../../src'
94

105
describe('RTDB: plugin options', () => {
116
it('allows customizing $rtdbBind', () => {
12-
const LocalVue = createLocalVue()
13-
LocalVue.use(rtdbPlugin, { bindName: '$bind', unbindName: '$unbind' })
14-
expect(typeof LocalVue.prototype.$bind).toBe('function')
15-
expect(typeof LocalVue.prototype.$unbind).toBe('function')
7+
const wrapper = mount(
8+
{ template: 'n' },
9+
{
10+
global: {
11+
plugins: [
12+
[
13+
rtdbPlugin,
14+
{
15+
bindName: '$myBind',
16+
unbindName: '$myUnbind',
17+
},
18+
],
19+
],
20+
},
21+
}
22+
)
23+
expect(typeof (wrapper.vm as any).$myBind).toBe('function')
24+
expect(typeof (wrapper.vm as any).$myUnbind).toBe('function')
1625
})
1726

1827
it('calls custom serialize function with collection', async () => {
19-
const LocalVue = createLocalVue()
2028
const pluginOptions = {
2129
serialize: jest.fn(() => ({ foo: 'bar' })),
2230
}
23-
LocalVue.use(rtdbPlugin, pluginOptions)
31+
const { vm } = mount(
32+
{
33+
template: 'no',
34+
data: () => ({ items: [] }),
35+
},
36+
{
37+
global: {
38+
plugins: [[rtdbPlugin, pluginOptions]],
39+
},
40+
}
41+
)
2442

2543
const items = new MockFirebase().child('data')
26-
const vm = new LocalVue({
27-
data: () => ({ items: [] }),
28-
})
2944

3045
const p = vm.$rtdbBind('items', items)
3146
items.push({ text: 'foo' })
@@ -41,16 +56,22 @@ describe('RTDB: plugin options', () => {
4156
})
4257

4358
it('can be ovrriden by local option', async () => {
44-
const LocalVue = createLocalVue()
4559
const pluginOptions = {
4660
serialize: jest.fn(() => ({ foo: 'bar' })),
4761
}
48-
LocalVue.use(rtdbPlugin, pluginOptions)
4962

5063
const items = new MockFirebase().child('data')
51-
const vm = new LocalVue({
52-
data: () => ({ items: [] }),
53-
})
64+
const { vm } = mount(
65+
{
66+
template: 'no',
67+
data: () => ({ items: [] }),
68+
},
69+
{
70+
global: {
71+
plugins: [[rtdbPlugin, pluginOptions]],
72+
},
73+
}
74+
)
5475

5576
const spy = jest.fn(() => ({ bar: 'bar' }))
5677

0 commit comments

Comments
 (0)