Skip to content

tepez/joi-jasmine-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

joi-jasmine-helpers

Custom matchers for writing unit test in Jasmine for hapijs/joi schemas and extensions

npm version

Install

npm install --save @tepez/joi-jasmine-helpers

Compatibility

Version Joi
1.x.x 17 joi
0.2.x 14 joi

Usage

describe('custom matchers', () => {
    JoiJasmineHelpers.addMatchers();

    it('toPassValidation', () => {
        const schema = Joi.number().integer();
        expect(schema).toPassValidation(100);
        expect(schema).toPassValidation('100');

        expect(schema).toPassValidation(100, 100);
        expect(schema).toPassValidation('100', 100);

        expect(schema).toPassValidation('100', 100, {
            convert: true,
        });
    });

    it('toFailValidation', () => {
        const schema = Joi.number().integer();
        expect(schema).toFailValidation('xxx');
        expect(schema).toFailValidation('xxx', '"value" must be a number');
        expect(schema).toFailValidation('xxx', /^"value" must be a number$/);
        expect(schema).toFailValidation(10.5, /^"value" must be an integer$/);

        expect(schema).toFailValidation('100', '"value" must be a number', {
            convert: false,
        });
    });
});

About

Custom matchers for writing unit test for https://github.com/hapijs/joi/ schemas and extensions

Resources

Stars

Watchers

Forks

Packages

No packages published