raisch / chai-joi Goto Github PK
View Code? Open in Web Editor NEWChai extensions for Joi validations.
License: MIT License
Chai extensions for Joi validations.
License: MIT License
It would be nice to have error message when it was expected to validate but didn't validate.
For example,
I have a validation that I expect to pass, but doesn't
It shows me
AssertionError: { Object (error, value) } should validate but does not
Could you bump the version of this project, now that the joi compatibility issue has been resolved?
I just downloaded the npm package and it has merge conflicts and an older version of lodash. I cannot use it. Fix it asap.
Current release is broken. download from NPM, it contains a merge conflict
Use joi: 13.1.1 or newer.
Example:
const chai = require('chai');
const joi = require('joi');
chai.should();
chai.use(require('chai-joi'));
describe('.should.validate', function() {
it('should validate', function() {
let schema = joi.object().keys({
'foo': joi.any().required(),
'bar': joi.number().required()
});
let data = {'foo': 'bar', 'bar': 5};
let result = joi.validate(data, schema);
console.log(result);
result.should.validate;
});
});
Output:
$ mocha -- test/api-validation-test.js
.should.validate
{ error: null,
value: { foo: 'bar', bar: 5 },
then: [Function: then],
catch: [Function: catch] }
1) should validate
0 passing (13ms)
1 failing
1) .should.validate
should validate:
AssertionError: { Object (error, value, ...) } is not a validation because it contains unexpected keys
at Function._chai.assert.isValidation (node_modules/chai-joi/index.js:232:34)
at Assertion.validate (node_modules/chai-joi/index.js:122:15)
at Assertion.propertyGetter (node_modules/chai/lib/chai/utils/addProperty.js:62:29)
at Object.get (<anonymous>)
at Object.proxyGetter [as get] (node_modules/chai/lib/chai/utils/proxify.js:86:22)
at Context.<anonymous> (test/api-validation-test.js:24:19)
Hello,
is this project still maintained, or is abandoned?
Thank you
Jan Opravil
Hi,
I'm trying to understand how this package is intended to be used.
I use Joi to validate API calls, whether these be restful endpoints or simply functions.
When testing my API, I will use Joi.attempt()
or Joi.assert()
to ensure the API doesn't accept undesired input.
What would be very helpful would be a helper for testing the exceptions. For example,
function foo(bar) {
Joi.assert(bar, Joi.string().required().min(4).label('bar').description('four-letter word'));
}
describe('foo()', () => {
it('should throw if not passed a four-letter word', () => {
// too basic
expect(() => foo('baz')).to.throw(Error);
// too coupled to Joi's API
expect(() => foo('baz')).to.throw('"bar" length must be at least 4 characters long');
// desired syntax, or something like it
expect(() => foo('baz')).to.throw(Error).with.type('string.min').and.path('bar');
});
});
Perhaps this is already possible without this addon.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.