forked from vuelidate/vuelidate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vuelidate#117] fix too eager validation evaluation on $error access
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/unit/specs/regression/#117-clean-error-evaluation.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |