Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
feat(validator): update warnning message
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Feb 9, 2016
1 parent f2fab0f commit c6495e0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/directives/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ export default function (Vue) {

bind () {
if (!this.params.name) {
// TODO: should be implemented validator:bind name params nothing error'
warn('TODO: should be implemented validator:bind name params nothing error')
warn('validator element directive need to specify \'name\' param attribute: ' +
'(e.g. <validator name="validator1">...</validator>)'
)
return
}

this.validatorName = '$' + camelize(this.params.name)
if (!this.vm._validatorMaps) {
// TODO: should be implemented error message'
warn('TODO: should be implemented error message')
return
throw new Error('Invalid validator management error')
}

this.setupValidator()
Expand Down
50 changes: 43 additions & 7 deletions test/specs/directives/validator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'power-assert'
import Vue from 'vue'
import Validator from '../../../src/directives/validator'
import { trigger, pull } from '../../../src/util'


Expand Down Expand Up @@ -30,20 +31,55 @@ describe('validator element directive', () => {
})


describe('invalid warn', () => {
context('not specify name attribute', () => {
it.skip('should be called warn', () => {
// TODO:
describe('warnning', () => {
let called = false
beforeEach(() => {
Validator.__Rewire__('warn', (msg, err) => {
called = true
})
})
context.skip('not exist validator map object in vm instance', () => {
it.skip('should be called warn', () => {
// TODO:

afterEach(() => {
Validator.__ResetDependency__('warn')
called = false
})

describe('name attribute', () => {
it('should be called warn', (done) => {
el.innerHTML = '<validator></validator>'
vm = new Vue({ el: el })
vm.$nextTick(() => {
assert(called === true)
done()
})
})
})
})


describe('internal validator management', () => {
let init
beforeEach(() => {
init = Vue.prototype._init
Vue.prototype._init = (options) => {
this._validatorMaps = null
init.call(this, options)
}
})

afterEach(() => {
Vue.prototype._init = init
})

it('should be occured error', () => {
el.innerHTML = '<validator name="validator1"></validator>'
assert.throws(() => {
vm = new Vue({ el: el })
}, Error)
})
})


describe('name attribute', () => {
context('kebab-case', () => {
beforeEach(() => {
Expand Down

0 comments on commit c6495e0

Please sign in to comment.