UNPKG

1.06 kBJavaScriptView Raw
1if (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
9describe('Validator', function () {
10 context('_flattenObject', function() {
11 it('should correctly flatten nested object', function() {
12 var asserts = [
13 [undefined, {}],
14 [null, {}],
15 [{}, {}],
16 [{ foo: null }, { foo: null }],
17 [{ foo: {} }, { foo: {} }],
18 [{ foo : 1 }, { foo : 1 }],
19 [{ foo : [] }, { foo : [] }],
20 [{ foo: { bar: 1 } }, { 'foo.bar' : 1 }],
21 [{ foo: { bar: [] } }, { 'foo.bar' : [] }],
22 [{ foo: { bar: { fizz: "buzz" } } }, { 'foo.bar.fizz' : "buzz" }],
23 [{ foo: { bar: { fizz: ["buzz"] } } }, { 'foo.bar.fizz' : ["buzz"] }]
24 ];
25 var validator = new Validator({}, {});
26
27 asserts.forEach(function (assert) {
28 expect(validator._flattenObject(assert[0])).to.be.eql(assert[1]);
29 });
30 });
31 });
32}); // Page constructor