Skip to content

Commit

Permalink
[vuelidate#117] fix too eager validation evaluation on $error access
Browse files Browse the repository at this point in the history
  • Loading branch information
Frizi committed Apr 6, 2017
1 parent 6105831 commit c3b1bc7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const validationGetters = {
})
},
$error () {
return !this.$pending && this.$dirty && this.$invalid
return this.$dirty && !this.$pending && this.$invalid
},
$pending () {
const proxy = this.proxy
Expand Down
34 changes: 34 additions & 0 deletions test/unit/specs/regression/#117-clean-error-evaluation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Vue from 'vue'

describe('#117 too eager evaluation', () => {
it('$error access should not trigger validation on clean field', () => {
const spy = sinon.stub().returns(true)
const vm = new Vue({
data: {
test: ''
},
validations: {
test: { spy }
}
})

expect(vm.$v.test.$error).to.be.false
expect(spy).to.not.have.been.called
})

it('$error access should trigger validation on dirty field', () => {
const spy = sinon.stub().returns(true)
const vm = new Vue({
data: {
test: ''
},
validations: {
test: { spy }
}
})

vm.$v.test.$touch()
expect(vm.$v.test.$error).to.be.false
expect(spy).to.have.been.calledOnce
})
})

0 comments on commit c3b1bc7

Please sign in to comment.