Completed
Push — master ( 17f83b...e9467a )
by Taavo-Taur
53s
created

test/aliases.test.js   A

Size

Lines of Code 86

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 86
rs 10
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
aliases.test.js ➔ ??? 0 36 ?
aliases.test.js ➔ makeBaseDriver 0 17 ?
1
import test from 'ava'
2
3
import aliasesMixinMaker from '../src/aliases'
4
5
import {addVueWithPlugin, vueCleanup} from './helpers/before/vue-hookup'
6
7
function makeBaseDriver() {
8
	return class TestDriver {
9
		constructor(Vue) {
10
			Vue.util.defineReactive(this, 'state', {})
11
			Vue.util.defineReactive(this, 'loading', true)
12
		}
13
14
		ready() {
15
		}
16
17
		destroy() {
18
		}
19
20
		refresh() {
21
		}
22
	}
23
}
24
25
test.afterEach(vueCleanup)
26
27
test('All aliases', t => {
28
	let testing = null
29
30
	class TestSyncer extends makeBaseDriver() {
31
		refresh() {
32
			t.is(testing, 'refresh')
33
		}
34
	}
35
36
	addVueWithPlugin(t, {
37
		aliases: true,
38
		driver: TestSyncer,
39
		feathers: {
40
			service(service) {
41
				t.is(testing, 'service')
42
				t.is(service, 'manual-test')
43
			}
44
		}
45
	})
46
	const {Vue} = t.context
47
48
	const instance = new Vue({
49
		sync: {
50
			test: 'test'
51
		}
52
	})
53
54
	testing = 'loading'
55
	t.is(instance.$loading, true)
56
57
	testing = 'refresh'
58
	instance.$refresh()
59
60
	testing = 'service'
61
	instance.$service('manual-test')
62
})
63
64
test('Toggling aliases', t => {
65
	addVueWithPlugin(t, {
66
		driver: makeBaseDriver(),
67
		feathers: {}
68
	})
69
	const {Vue} = t.context
70
71
	Vue.mixin(aliasesMixinMaker({
72
		loading: false,
73
		refresh: true
74
		// service: false is implied
75
	}))
76
77
	const instance = new Vue({
78
		sync: {
79
			test: 'test'
80
		}
81
	})
82
83
	t.is(typeof instance.$loading, 'undefined')
84
	t.is(typeof instance.$refresh, 'function')
85
	t.is(typeof instance.$service, 'undefined')
86
})
87