Completed
Push — master ( 7403a2...9afade )
by Taavo-Taur
02:16
created

test/core.test.js   A

Size

Lines of Code 106

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 1
dl 0
loc 106
rs 10
noi 0
1
import test from 'ava'
2
import {addVueWithPlugin, vueCleanup} from './helpers/before/vue-hookup'
3
4
function makeBaseDriver() {
5
	return class TestDriver {
6
		constructor(Vue) {
7
			Vue.util.defineReactive(this, 'state', {})
8
		}
9
10
		ready() {
11
		}
12
13
		destroy() {
14
		}
15
	}
16
}
17
18
test.beforeEach(t => {
19
	addVueWithPlugin(t, {driver: makeBaseDriver(), feathers: {}})
20
})
21
22
test.afterEach(vueCleanup)
23
24
test.cb('Syncer lifecycle methods are called in right order', t => {
25
	const Vue = t.context.Vue
26
27
	t.plan(7)
28
	let order = 0
29
30
	class TestSyncer extends makeBaseDriver() {
31
		constructor(Vue) {
32
			super(Vue)
33
34
			t.is(order++, 0, 'Syncer instance set up')
35
		}
36
37
		ready() {
38
			super.ready()
39
40
			t.is(order++, 2, 'Syncer can be ready')
41
		}
42
43
		destroy() {
44
			super.destroy()
45
46
			t.is(order++, 4, 'Syncer being destroyed')
47
		}
48
	}
49
50
	Vue.$syncer.driver = TestSyncer
51
52
	const instance = new Vue({
53
		beforeCreate: function () {
54
			t.is(order++, 1, 'Vue instance created')
55
		},
56
57
		created: function () {
58
			// no ready in node mode
59
			t.is(order++, 3, 'Vue instance is ready')
60
61
			Vue.util.nextTick(function () {
62
				instance.$destroy()
63
			})
64
		},
65
66
		beforeDestroy: function () {
67
			t.is(order++, 5, 'Vue instance being destroyed')
68
		},
69
70
		destroyed: function () {
71
			t.is(order++, 6, 'Vue instance is destroyed')
72
73
			Vue.util.nextTick(function () {
74
				// Make sure hook doesn't cause double cleanup for any weird reason
75
				instance.$destroy()
76
77
				Vue.util.nextTick(function () {
78
					t.end()
79
				})
80
			})
81
		},
82
83
		sync: {
84
			test: 'test'
85
		}
86
	})
87
})
88
89
test.cb('Non-used instances work fine', t => {
90
	const Vue = t.context.Vue
91
92
	t.truthy(Vue.$syncer)
93
94
	const instance = new Vue({
95
		destroyed: function () {
96
			t.pass()
97
98
			Vue.util.nextTick(function () {
99
				t.end()
100
			})
101
		}
102
	})
103
	// No syncers = not loading
104
	t.falsy(instance.$loadingSyncers)
105
	instance.$destroy()
106
})
107