|
1 | 1 | # chai-json-schema
|
2 | 2 |
|
3 |
| -[](http://travis-ci.org/Bartvds/chai-json-schema) [](https://gemnasium.com/Bartvds/chai-json-schema) [](http://badge.fury.io/js/chai-json-schema) |
| 3 | +[](https://travis-ci.org/chaijs/chai-json-schema) |
| 4 | +[](https://www.npmjs.com/packages/chai-json-schema) |
| 5 | +[](https://www.npmjs.com/packages/chai-json-schema) |
4 | 6 |
|
5 | 7 | > [Chai](http://chaijs.com/) plugin with assertions to validate values against [JSON Schema v4](http://json-schema.org/).
|
6 | 8 |
|
@@ -63,36 +65,36 @@ Validate that the given javascript value conforms to the specified JSON Schema.
|
63 | 65 |
|
64 | 66 | ````js
|
65 | 67 | var goodApple = {
|
66 |
| - skin: "thin", |
67 |
| - colors: ["red", "green", "yellow"], |
68 |
| - taste: 10 |
| 68 | + skin: 'thin', |
| 69 | + colors: ['red', 'green', 'yellow'], |
| 70 | + taste: 10 |
69 | 71 | };
|
70 | 72 | var badApple = {
|
71 |
| - colors: ["brown"], |
72 |
| - taste: 0, |
73 |
| - worms: 2 |
| 73 | + colors: ['brown'], |
| 74 | + taste: 0, |
| 75 | + worms: 2 |
74 | 76 | };
|
75 | 77 | var fruitSchema = {
|
76 |
| - "title": "fresh fruit schema v1", |
77 |
| - "type": "object", |
78 |
| - "required": ["skin", "colors", "taste"], |
79 |
| - "properties": { |
80 |
| - "colors": { |
81 |
| - "type": "array", |
82 |
| - "minItems": 1, |
83 |
| - "uniqueItems": true, |
84 |
| - "items": { |
85 |
| - "type": "string" |
86 |
| - } |
87 |
| - }, |
88 |
| - "skin": { |
89 |
| - "type": "string" |
90 |
| - }, |
91 |
| - "taste": { |
92 |
| - "type": "number", |
93 |
| - "minimum": 5 |
94 |
| - } |
95 |
| - } |
| 78 | + title: 'fresh fruit schema v1', |
| 79 | + type: 'object', |
| 80 | + required: ['skin', 'colors', 'taste'], |
| 81 | + properties: { |
| 82 | + colors: { |
| 83 | + type: 'array', |
| 84 | + minItems: 1, |
| 85 | + uniqueItems: true, |
| 86 | + items: { |
| 87 | + type: 'string' |
| 88 | + } |
| 89 | + }, |
| 90 | + skin: { |
| 91 | + type: 'string' |
| 92 | + }, |
| 93 | + taste: { |
| 94 | + type: 'number', |
| 95 | + minimum: 5 |
| 96 | + } |
| 97 | + } |
96 | 98 | };
|
97 | 99 |
|
98 | 100 | //bdd style
|
@@ -164,41 +166,41 @@ Use the asynchronous preparation feature of your favourite test runner to preloa
|
164 | 166 |
|
165 | 167 | before(function (done) {
|
166 | 168 |
|
167 |
| - // iterate missing |
168 |
| - var checkMissing = function (callback) { |
169 |
| - var missing = chai.tv4.getMissingUris(); |
170 |
| - if (missing.length === 0) { |
171 |
| - // all $ref's solved |
172 |
| - callback(); |
173 |
| - return; |
174 |
| - } |
175 |
| - // load a schema using your favourite JSON loader |
176 |
| - // (jQuery, request, SuperAgent etc) |
177 |
| - var uri = missing.pop(); |
178 |
| - myFavoriteJsonLoader.load(uri, function (err, schema) { |
179 |
| - if (err || !schema) { |
180 |
| - callback(err || 'no data loaded'); |
181 |
| - return; |
182 |
| - } |
183 |
| - // add it |
184 |
| - chai.tv4.addSchema(uri, schema); |
185 |
| - // iterate |
186 |
| - checkMissing(callback); |
187 |
| - }); |
188 |
| - }; |
189 |
| - |
190 |
| - // load first instance manually |
| 169 | + // iterate missing |
| 170 | + var checkMissing = function (callback) { |
| 171 | + var missing = chai.tv4.getMissingUris(); |
| 172 | + if (missing.length === 0) { |
| 173 | + // all $ref's solved |
| 174 | + callback(); |
| 175 | + return; |
| 176 | + } |
| 177 | + // load a schema using your favourite JSON loader |
| 178 | + // (jQuery, request, SuperAgent etc) |
| 179 | + var uri = missing.pop(); |
191 | 180 | myFavoriteJsonLoader.load(uri, function (err, schema) {
|
192 |
| - if (err || !schema) { |
193 |
| - done(err || 'no data loaded'); |
194 |
| - return; |
195 |
| - } |
196 |
| - // add it |
197 |
| - chai.tv4.addSchema(uri, schema); |
198 |
| - |
199 |
| - // start checking |
200 |
| - checkMissing(done); |
| 181 | + if (err || !schema) { |
| 182 | + callback(err || 'no data loaded'); |
| 183 | + return; |
| 184 | + } |
| 185 | + // add it |
| 186 | + chai.tv4.addSchema(uri, schema); |
| 187 | + // iterate |
| 188 | + checkMissing(callback); |
201 | 189 | });
|
| 190 | + }; |
| 191 | + |
| 192 | + // load first instance manually |
| 193 | + myFavoriteJsonLoader.load(uri, function (err, schema) { |
| 194 | + if (err || !schema) { |
| 195 | + done(err || 'no data loaded'); |
| 196 | + return; |
| 197 | + } |
| 198 | + // add it |
| 199 | + chai.tv4.addSchema(uri, schema); |
| 200 | + |
| 201 | + // start checking |
| 202 | + checkMissing(done); |
| 203 | + }); |
202 | 204 | });
|
203 | 205 | ````
|
204 | 206 |
|
|
0 commit comments