Skip to content

Commit

Permalink
refactor(lint): fix lint in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Nov 19, 2017
1 parent 6309e3c commit b5342a6
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 94 deletions.
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
newTodoText: ''
},
firestore: {
todos,
todos: todos.where('finished', '==', false),
config
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"README.md"
],
"scripts": {
"lint": "eslint --ext=js,html src tests examples",
"lint": "eslint --ext=js,html src test examples",
"build": "node build/build.js",
"pretest": "npm run lint",
"test": "npm run unit",
Expand Down
7 changes: 2 additions & 5 deletions test/bind.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import test from 'ava'
import Vuefire from '../src'
import {
createSnapshot
} from '../src/utils'
import {
db,
tick,
Expand All @@ -24,8 +21,8 @@ test.beforeEach(async t => {
// but it's a good practice to set it to an empty array
data: () => ({
items: null,
item: null,
}),
item: null
})
}).$mount()
await tick()
})
Expand Down
3 changes: 0 additions & 3 deletions test/collection.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import test from 'ava'
import sinon from 'sinon'
import Vuefire from '../src'
import {
createSnapshot
} from '../src/utils'
import {
db,
tick,
Expand Down
5 changes: 1 addition & 4 deletions test/document.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import test from 'ava'
import Vuefire from '../src'
import {
createSnapshot
} from '../src/utils'
import {
db,
tick,
Expand All @@ -24,7 +21,7 @@ test.beforeEach(async t => {
// but it's a good practice to set it to an empty array
data: () => ({
items: null,
item: null,
item: null
}),
firestore: {
items: t.context.collection,
Expand Down
28 changes: 15 additions & 13 deletions test/helpers/mock.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export class DocumentSnapshot {
constructor (firestore, key, document) {
this._firestore = firestore;
this._key = key;
this._document = document;
this._firestore = firestore
this._key = key
this._document = document
}

data () {
Expand Down Expand Up @@ -41,10 +41,11 @@ class DocumentReference {
onSnapshot (cb, onError) {
this.cb = cb
this.onError = onError
return () => this.cb = this.onError = noop
return () => {
this.cb = this.onError = noop
}
}


async delete () {
return this.collection._remove(this.id)
}
Expand All @@ -65,7 +66,9 @@ class CollectionReference {
onSnapshot (cb, onError) {
this.cb = cb
this.onError = onError
return () => this.cb = this.onError = noop
return () => {
this.cb = this.onError = noop
}
}

async add (data) {
Expand All @@ -81,7 +84,7 @@ class CollectionReference {
type: 'added',
doc: new DocumentSnapshot(null, id, data),
newIndex: Object.keys(this.data).length,
oldIndex: -1,
oldIndex: -1
}]
})
return this.data[id]
Expand All @@ -92,12 +95,12 @@ class CollectionReference {

doc (id) {
id = id || new Key()
return this.data[id] = this.data[id] || new DocumentReference({
return (this.data[id] = this.data[id] || new DocumentReference({
collection: this,
id,
data: {},
index: Object.keys(this.data).length
})
}))
}

async _remove (id) {
Expand All @@ -106,7 +109,7 @@ class CollectionReference {
this.cb({
docChanges: [{
doc: new DocumentSnapshot(null, id, ref.data),
type: 'removed',
type: 'removed'
}]
})
ref.collection = null
Expand All @@ -119,10 +122,9 @@ class CollectionReference {
type: 'modified',
doc: new DocumentSnapshot(null, id, data),
oldIndex: this.data[id].index,
newIndex: this.data[id].index,
newIndex: this.data[id].index
}]
})

}
}

Expand All @@ -133,6 +135,6 @@ export const db = {
collection (name) {
// create a collection if no name provided
name = name || `random__${this.n++}`
return db[name] = db[name] || new CollectionReference()
return (db[name] = db[name] || new CollectionReference())
}
}
54 changes: 1 addition & 53 deletions test/helpers/wait-for-update.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,5 @@
import Vue from 'vue'

// Testing helper
// nextTick().then(() => {
//
// Automatically waits for nextTick
// }).then(() => {
// return a promise or value to skip the wait
// })
function oldtick () {
const jobs = []
let done

const chainer = {
then (cb) {
jobs.push(cb)
return chainer
},
}

function shift (...args) {
const job = jobs.shift()
let result
try {
result = job(...args)
} catch (e) {
jobs.length = 0
done(e)
}

// wait for nextTick
if (result !== undefined) {
if (result.then) {
result.then(shift)
} else {
shift(result)
}
} else if (jobs.length) {
requestAnimationFrame(() => Vue.nextTick(shift))
}
}

// First time
Vue.nextTick(() => {
done = jobs[jobs.length - 1]
if (done && done.toString().slice(0, 14) !== 'function (err)') {
throw new Error('waitForUpdate chain is missing .then(done)')
}
shift()
})

return chainer
}

function tick () {
return new Promise((resolve, reject) => {
Vue.nextTick(resolve)
Expand All @@ -65,5 +13,5 @@ function delay (time) {
export {
tick,
delay,
Vue,
Vue
}
13 changes: 5 additions & 8 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import test from 'ava'
import Vuefire from '../src'
import {
createSnapshot
} from '../src/utils'
import {
db,
tick,
Expand All @@ -24,7 +21,7 @@ test.beforeEach(async t => {
// but it's a good practice to set it to an empty array
data: () => ({
items: null,
item: null,
item: null
}),
firestore: {
items: t.context.collection,
Expand All @@ -36,8 +33,8 @@ test.beforeEach(async t => {

test('does nothing with no firestore', t => {
const vm = new Vue({
render: h => ('p', 'foo'),
data: () => ({ items: null }),
render: h => h('p', 'foo'),
data: () => ({ items: null })
})
t.deepEqual(vm.items, null)
})
Expand All @@ -50,8 +47,8 @@ test('setups _firestoreUnbinds', t => {

test('setups _firestoreUnbinds with no firestore options', t => {
const vm = new Vue({
render: h => ('p', 'foo'),
data: () => ({ items: null }),
render: h => h('p', 'foo'),
data: () => ({ items: null })
})
t.truthy(vm._firestoreUnbinds)
t.deepEqual(Object.keys(vm._firestoreUnbinds), [])
Expand Down
5 changes: 1 addition & 4 deletions test/unbind.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import test from 'ava'
import sinon from 'sinon'
import Vuefire from '../src'
import {
createSnapshot
} from '../src/utils'
import {
db,
tick,
Expand All @@ -25,7 +22,7 @@ test.beforeEach(async t => {
// but it's a good practice to set it to an empty array
data: () => ({
items: null,
item: null,
item: null
}),
firestore: {
items: t.context.collection,
Expand Down
3 changes: 1 addition & 2 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import test from 'ava'
import {
createSnapshot,
createSnapshot
} from '../src/utils'
import {
collection,
Key,
id,
DocumentSnapshot
Expand Down

0 comments on commit b5342a6

Please sign in to comment.