Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Validator {

this._validator = validate
this._errors = Object.create(null)
this.hasValidated = false;
}


Expand All @@ -34,6 +35,10 @@ class Validator {
this._removeError(name)

return Promise.all(fields)
.then(fields => {
this.hasValidated = true
return fields
})
}

_validateField(name, context){
Expand All @@ -58,4 +63,4 @@ class Validator {
}
}

module.exports = Validator
module.exports = Validator
15 changes: 12 additions & 3 deletions test/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('validator', function(){
spy.should.have.been.calledWithExactly('field', context)
})
})

it('should use passed in validation function', () => {
var spy
, context = {}
Expand Down Expand Up @@ -63,12 +63,21 @@ describe('validator', function(){
return validator.validate('fieldA').should.be.fulfilled
.then(() => {
validator.errors().should.have.key('fieldA')

return validator.validate('fieldA').should.be.fulfilled
.then(() => {
validator.errors().should.not.have.key('fieldA')
})
})
})
})

it('should track initial validation state', () => {
var validator = new Validator( field => 'invalid')
validator.hasValidated.should.equal(false)

return validator.validate('fieldA').should.be.fulfilled
.then(() => {
validator.hasValidated.should.equal(true)
})
})
})