Skip to content

Commit

Permalink
First tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mokkabonna committed Sep 17, 2017
1 parent dc037d6 commit e4def79
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"extends": "standard",
"rules": {
"space-before-function-paren": ["error", {
"anonymous": "ignore",
"named": "ignore",
"asyncArrow": "ignore"
}],
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=4"
},
"scripts": {
"test": "eslint ."
"test": "eslint . && mocha test"
},
"files": [
"index.js"
Expand All @@ -24,11 +24,14 @@
"dependencies": {},
"devDependencies": {
"ava": "^0.20.0",
"chai": "^4.1.2",
"eslint": "^4.7.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-standard": "^3.0.1",
"mocha": "^3.5.3",
"nyc": "^11.0.0",
"vue": "^2.4.4",
"xo": "^0.18.2"
}
}
45 changes: 37 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
import test from 'ava'
import m from '.'
/* global describe, it */
var expect = require('chai').expect
var Vue = require('vue')
var asyncMethods = require('./index')
var resolve
var reject

test('title', t => {
const err = t.throws(() => {
m(123)
}, TypeError)
t.is(err.message, 'Expected a string, got number')
function fetch() {
return new Promise(function(res, rej) {
resolve = res
reject = rej
})
}

t.is(m('unicorns'), 'unicorns & rainbows')
describe('vue-async-methods', function() {
var vm
beforeEach(function() {
Vue.use(asyncMethods)
vm = new Vue({
asyncMethods: {
fetch: fetch
}
})
})

it('creates the method object on the vm', function() {
expect(vm.fetch.execute).to.be.a('function')
})

it('exposes the initial state', function() {
expect(vm.fetch.isCalled).to.equal(false)
expect(vm.fetch.isPending).to.equal(false)
expect(vm.fetch.isResolved).to.equal(false)
expect(vm.fetch.isRejected).to.equal(false)
expect(vm.fetch.resolvedWith).to.equal(null)
expect(vm.fetch.resolvedWithSomething).to.equal(false)
expect(vm.fetch.resolvedWithEmpty).to.equal(false)
expect(vm.fetch.rejectedWith).to.equal(null)
})
})

0 comments on commit e4def79

Please sign in to comment.