Skip to content

Commit 67d69df

Browse files
committed
add tests for multiple option
1 parent e2c67ae commit 67d69df

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133

134134
// single result
135135
var result = null;
136-
if(chai.tv4.multiple) {
136+
if (chai.tv4.multiple) {
137137
result = chai.tv4.validateMultiple(obj, schema, chai.tv4.cyclicCheck, chai.tv4.banUnknown);
138138
} else {
139139
result = chai.tv4.validateResult(obj, schema, chai.tv4.cyclicCheck, chai.tv4.banUnknown);

test/suite.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
}],
8080
invalid: [{
8181
data: {
82-
intKey: 3,
82+
intKey: 'three',
8383
stringKey: false
8484
}
8585
}]
@@ -130,24 +130,25 @@
130130
data: {
131131
skin: 'thin',
132132
colors: ['yellow'],
133-
taste: 0
133+
taste: 0,
134+
worms: 2
134135
}
135136
}, {
136137
data: {
137138
skin: 'thin',
138139
colors: [1, 2, 3],
139-
taste: 5
140+
taste: 4
140141
}
141142
}, {
142143
data: {
143144
skin: 321,
144-
colors: ['yellow'],
145+
colors: ['yellow', 'yellow'],
145146
taste: 5
146147
}
147148
}, { data: {
148149
skin: 'thin',
149150
colors: ['yellow'],
150-
taste: 5,
151+
taste: 4,
151152
worms: 3
152153
}
153154
}]
@@ -214,6 +215,34 @@
214215
}).to.fail('#' + i);
215216
});
216217
});
218+
it('should/expect output single negation', function () {
219+
testCase.invalid.forEach(function (obj, i) {
220+
expect(function () {
221+
expect(obj.data).to.be.jsonSchema(testCase.schema, 'expect() #' + i);
222+
}).to.throw(/(.+?\n){4}/);
223+
expect(function () {
224+
obj.data.should.be.jsonSchema(testCase.schema, 'should #' + i);
225+
}).to.throw(/(.+?\n){4}/);
226+
});
227+
});
228+
describe('should/expect output multiple negation', function () {
229+
before(function () {
230+
chai.tv4.multiple = true;
231+
});
232+
after(function () {
233+
chai.tv4.multiple = false;
234+
});
235+
it('should/expect multiple negation', function () {
236+
testCase.invalid.forEach(function (obj, i) {
237+
expect(function () {
238+
expect(obj.data).to.be.jsonSchema(testCase.schema, 'expect() #' + i);
239+
}).to.throw(/(.+?\n){5,}/);
240+
expect(function () {
241+
obj.data.should.be.jsonSchema(testCase.schema, 'should #' + i);
242+
}).to.throw(/(.+?\n){5,}/);
243+
});
244+
});
245+
});
217246
});
218247
});
219248
});
@@ -252,6 +281,28 @@
252281
}).to.fail('#' + i);
253282
});
254283
});
284+
it('should/expect output single negation', function () {
285+
testCase.invalid.forEach(function (obj, i) {
286+
expect(function () {
287+
assert.jsonSchema(obj.data, testCase.schema, '#' + i);
288+
}).to.throw(/(.+?\n){4}/);
289+
});
290+
});
291+
describe('should/expect output multiple negation', function () {
292+
before(function () {
293+
chai.tv4.multiple = true;
294+
});
295+
after(function () {
296+
chai.tv4.multiple = false;
297+
});
298+
it('should/expect multiple negation', function () {
299+
testCase.invalid.forEach(function (obj, i) {
300+
expect(function () {
301+
assert.jsonSchema(obj.data, testCase.schema, '#' + i);
302+
}).to.throw(/(.+?\n){5,}/);
303+
});
304+
});
305+
});
255306
});
256307
});
257308
});

0 commit comments

Comments
 (0)