Coder Social home page Coder Social logo

chai-joi's People

Contributors

duereg avatar raisch avatar rob-raisch-simplisafe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

duereg sschimmel

chai-joi's Issues

Show error message when validation fails

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

Need new version

Could you bump the version of this project, now that the joi compatibility issue has been resolved?

npm package

I just downloaded the npm package and it has merge conflicts and an older version of lodash. I cannot use it. Fix it asap.

chai-joi not compatible with Joi >= 13.1.1

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)

Project maintenance

Hello,

is this project still maintained, or is abandoned?

Thank you
Jan Opravil

question: use case

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.