JSON-Schema-Faker performs two types of testing: unit and schema.
- They just validate the building blocks from the entire library
- We're using
mocha
andchai
so the worflow would be very familiar
Much stuff from the internals are not covered by unit-tests yet, PRs for increasing that are very welcome!
- Kind of functional tests, high-level - executing the whole
jsf
engine to generate fake data against given JSON Schema and checking the quality of the results - We are using
.json
files to describe the entire testing suite
Those .json
files look like the following:
[
{
"description": "Feature or issue description",
"tests": [
{
"description": "Single test description",
"schema": { ... },
...
}
]
},
...
]
Basically it will execute this for you:
describe('Feature or issue description', () => {
it('Single test description', () => {
// ...
});
});
The properties below are used to setup the test and execute the assertions:
-
setup
refs
— are for resolving used$ref
's on the faked schemarequire:{String|Array<String>}
— a path or list of paths relative to the spec directoryschema:{Object}
— the main used schema to fake and testseed
— provide the given seed to therandom()
generatorset
— configure given options throughjsf.option()
-
assertion
check:{Object}
— asserts the output matches a custom schema. Usevalid
to check against the originalschema
propertycount:{Integer}
— asserts against array length or the number of object propertiesequal:{Any}
— performs a deep equal assertion between generated data and the given valuehasNot:{Any}
— performs anot.toContain()
testhasProps:{Array<String>}
— asserts object has all props or each object of array has all propslength:{Integer}
— asserts on array lengthminProps{Array<Integer>}
: will count the number of object properties on each test iteration. For each integer provided, if that count was not reached at least, once then the test will failnotEmpty{Array<String>}
: asserts that each object property is not undefined or an empty array. Use strings with '.' for asserting on nested object propertiesonlyProps:{Array<String>}
— asserts that the object only has these propertiesthrows:{String|Boolean}
— assert on error message or that an error was thrown or not thrownthrowsSometimes:{String|Boolean}
— assert on error message or that an error was thrown. Will fail if it throws the wrong error or if it never throwstype:{String}
— used for primitives, it will perform atoHaveType()
testvalid:{true}
— tests the generated data against the original schema
-
debug
dump:{true|'bail'}
— prints the generated data. Will return immediately if set to 'bail'
-
execution
only:{true}
— run this test onlyrepeat:{Integer}
— will execute the same test many times as givenskip:{true}
— skip individual teststimeout:{Integer}
— set a custom timeout for the test
Use these tests as reference of how things works, if you found an edge-case please add it as test and open an issue for.