unexpected
unexpected copied to clipboard
unexpected-json-schema
Below works
import expect from 'unexpected'
import tv4 from 'tv4'
import fs from 'fs'
expect.addAssertion('<any> [not] to match json schema <string>', (expect, subject, path) => {
return expect.promise((run) => {
fs.readFile(`${__dirname}/schema/${path}.json`, { encoding: 'utf8' }, run((err, data) => {
if (err) throw err
const result = tv4.validate(subject, JSON.parse(data))
expect.subjectOutput = function (output) {
output.text(tv4.error.schemaPath)
}
expect.argsOutput = function (output) {
output.text(tv4.error.message)
}
return expect(result, '[not] to be true')
}))
})
})
That looks really sweet! You should turn that into a plugin.
I wonder if it would be possible to have a json schema to unexpected assertion converter, which would add all the benefits of diffing and error messages from unexpected
@Munter That's a great idea. The tv4 implementation seems rather involved, though, so it's probably not an easy task.
@b3njamin awesome idea.
@b3njamin do you want one of use to make the plugin, or do you want the honour youself?