1 | if (typeof require !== 'undefined') {
|
2 | var Validator = require('../src/validator.js');
|
3 | var expect = require('chai').expect;
|
4 | } else {
|
5 | var Validator = window.Validator;
|
6 | var expect = window.chai.expect;
|
7 | }
|
8 |
|
9 | describe('passes()', function() {
|
10 | it('should not duplicate error messages when called multiple times', function() {
|
11 | var validator = new Validator({}, {
|
12 | login: 'required'
|
13 | });
|
14 |
|
15 | validator.passes();
|
16 | validator.passes();
|
17 |
|
18 | expect(validator.errors.all()).to.eql({
|
19 | login: [
|
20 | 'The login field is required.'
|
21 | ]
|
22 | });
|
23 | });
|
24 |
|
25 | it('should work if the input doesn\'t extend Object', function () {
|
26 |
|
27 | var body = Object.create(null);
|
28 | body.a = 2;
|
29 |
|
30 | var validator = new Validator(body, {'a': 'required'});
|
31 |
|
32 | expect(validator.passes()).to.be.true;
|
33 | expect(validator.fails()).to.be.false;
|
34 | });
|
35 | });
|