Skip to content

Commit b5342a6

Browse files
committed
refactor(lint): fix lint in tests
1 parent 6309e3c commit b5342a6

10 files changed

+28
-94
lines changed

examples/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
newTodoText: ''
6767
},
6868
firestore: {
69-
todos,
69+
todos: todos.where('finished', '==', false),
7070
config
7171
},
7272
methods: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"README.md"
1313
],
1414
"scripts": {
15-
"lint": "eslint --ext=js,html src tests examples",
15+
"lint": "eslint --ext=js,html src test examples",
1616
"build": "node build/build.js",
1717
"pretest": "npm run lint",
1818
"test": "npm run unit",

test/bind.spec.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import test from 'ava'
22
import Vuefire from '../src'
3-
import {
4-
createSnapshot
5-
} from '../src/utils'
63
import {
74
db,
85
tick,
@@ -24,8 +21,8 @@ test.beforeEach(async t => {
2421
// but it's a good practice to set it to an empty array
2522
data: () => ({
2623
items: null,
27-
item: null,
28-
}),
24+
item: null
25+
})
2926
}).$mount()
3027
await tick()
3128
})

test/collection.spec.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import test from 'ava'
22
import sinon from 'sinon'
33
import Vuefire from '../src'
4-
import {
5-
createSnapshot
6-
} from '../src/utils'
74
import {
85
db,
96
tick,

test/document.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import test from 'ava'
22
import Vuefire from '../src'
3-
import {
4-
createSnapshot
5-
} from '../src/utils'
63
import {
74
db,
85
tick,
@@ -24,7 +21,7 @@ test.beforeEach(async t => {
2421
// but it's a good practice to set it to an empty array
2522
data: () => ({
2623
items: null,
27-
item: null,
24+
item: null
2825
}),
2926
firestore: {
3027
items: t.context.collection,

test/helpers/mock.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export class DocumentSnapshot {
22
constructor (firestore, key, document) {
3-
this._firestore = firestore;
4-
this._key = key;
5-
this._document = document;
3+
this._firestore = firestore
4+
this._key = key
5+
this._document = document
66
}
77

88
data () {
@@ -41,10 +41,11 @@ class DocumentReference {
4141
onSnapshot (cb, onError) {
4242
this.cb = cb
4343
this.onError = onError
44-
return () => this.cb = this.onError = noop
44+
return () => {
45+
this.cb = this.onError = noop
46+
}
4547
}
4648

47-
4849
async delete () {
4950
return this.collection._remove(this.id)
5051
}
@@ -65,7 +66,9 @@ class CollectionReference {
6566
onSnapshot (cb, onError) {
6667
this.cb = cb
6768
this.onError = onError
68-
return () => this.cb = this.onError = noop
69+
return () => {
70+
this.cb = this.onError = noop
71+
}
6972
}
7073

7174
async add (data) {
@@ -81,7 +84,7 @@ class CollectionReference {
8184
type: 'added',
8285
doc: new DocumentSnapshot(null, id, data),
8386
newIndex: Object.keys(this.data).length,
84-
oldIndex: -1,
87+
oldIndex: -1
8588
}]
8689
})
8790
return this.data[id]
@@ -92,12 +95,12 @@ class CollectionReference {
9295

9396
doc (id) {
9497
id = id || new Key()
95-
return this.data[id] = this.data[id] || new DocumentReference({
98+
return (this.data[id] = this.data[id] || new DocumentReference({
9699
collection: this,
97100
id,
98101
data: {},
99102
index: Object.keys(this.data).length
100-
})
103+
}))
101104
}
102105

103106
async _remove (id) {
@@ -106,7 +109,7 @@ class CollectionReference {
106109
this.cb({
107110
docChanges: [{
108111
doc: new DocumentSnapshot(null, id, ref.data),
109-
type: 'removed',
112+
type: 'removed'
110113
}]
111114
})
112115
ref.collection = null
@@ -119,10 +122,9 @@ class CollectionReference {
119122
type: 'modified',
120123
doc: new DocumentSnapshot(null, id, data),
121124
oldIndex: this.data[id].index,
122-
newIndex: this.data[id].index,
125+
newIndex: this.data[id].index
123126
}]
124127
})
125-
126128
}
127129
}
128130

@@ -133,6 +135,6 @@ export const db = {
133135
collection (name) {
134136
// create a collection if no name provided
135137
name = name || `random__${this.n++}`
136-
return db[name] = db[name] || new CollectionReference()
138+
return (db[name] = db[name] || new CollectionReference())
137139
}
138140
}

test/helpers/wait-for-update.js

+1-53
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,5 @@
11
import Vue from 'vue'
22

3-
// Testing helper
4-
// nextTick().then(() => {
5-
//
6-
// Automatically waits for nextTick
7-
// }).then(() => {
8-
// return a promise or value to skip the wait
9-
// })
10-
function oldtick () {
11-
const jobs = []
12-
let done
13-
14-
const chainer = {
15-
then (cb) {
16-
jobs.push(cb)
17-
return chainer
18-
},
19-
}
20-
21-
function shift (...args) {
22-
const job = jobs.shift()
23-
let result
24-
try {
25-
result = job(...args)
26-
} catch (e) {
27-
jobs.length = 0
28-
done(e)
29-
}
30-
31-
// wait for nextTick
32-
if (result !== undefined) {
33-
if (result.then) {
34-
result.then(shift)
35-
} else {
36-
shift(result)
37-
}
38-
} else if (jobs.length) {
39-
requestAnimationFrame(() => Vue.nextTick(shift))
40-
}
41-
}
42-
43-
// First time
44-
Vue.nextTick(() => {
45-
done = jobs[jobs.length - 1]
46-
if (done && done.toString().slice(0, 14) !== 'function (err)') {
47-
throw new Error('waitForUpdate chain is missing .then(done)')
48-
}
49-
shift()
50-
})
51-
52-
return chainer
53-
}
54-
553
function tick () {
564
return new Promise((resolve, reject) => {
575
Vue.nextTick(resolve)
@@ -65,5 +13,5 @@ function delay (time) {
6513
export {
6614
tick,
6715
delay,
68-
Vue,
16+
Vue
6917
}

test/index.spec.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import test from 'ava'
22
import Vuefire from '../src'
3-
import {
4-
createSnapshot
5-
} from '../src/utils'
63
import {
74
db,
85
tick,
@@ -24,7 +21,7 @@ test.beforeEach(async t => {
2421
// but it's a good practice to set it to an empty array
2522
data: () => ({
2623
items: null,
27-
item: null,
24+
item: null
2825
}),
2926
firestore: {
3027
items: t.context.collection,
@@ -36,8 +33,8 @@ test.beforeEach(async t => {
3633

3734
test('does nothing with no firestore', t => {
3835
const vm = new Vue({
39-
render: h => ('p', 'foo'),
40-
data: () => ({ items: null }),
36+
render: h => h('p', 'foo'),
37+
data: () => ({ items: null })
4138
})
4239
t.deepEqual(vm.items, null)
4340
})
@@ -50,8 +47,8 @@ test('setups _firestoreUnbinds', t => {
5047

5148
test('setups _firestoreUnbinds with no firestore options', t => {
5249
const vm = new Vue({
53-
render: h => ('p', 'foo'),
54-
data: () => ({ items: null }),
50+
render: h => h('p', 'foo'),
51+
data: () => ({ items: null })
5552
})
5653
t.truthy(vm._firestoreUnbinds)
5754
t.deepEqual(Object.keys(vm._firestoreUnbinds), [])

test/unbind.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import test from 'ava'
22
import sinon from 'sinon'
33
import Vuefire from '../src'
4-
import {
5-
createSnapshot
6-
} from '../src/utils'
74
import {
85
db,
96
tick,
@@ -25,7 +22,7 @@ test.beforeEach(async t => {
2522
// but it's a good practice to set it to an empty array
2623
data: () => ({
2724
items: null,
28-
item: null,
25+
item: null
2926
}),
3027
firestore: {
3128
items: t.context.collection,

test/utils.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import test from 'ava'
22
import {
3-
createSnapshot,
3+
createSnapshot
44
} from '../src/utils'
55
import {
6-
collection,
76
Key,
87
id,
98
DocumentSnapshot

0 commit comments

Comments
 (0)