1.1.0 • Published 9 months ago

@tepez/joi-jasmine-helpers v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
9 months ago

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

VersionJoi
1.x.x17 joi
0.2.x14 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,
        });
    });
});
1.1.0

9 months ago

1.0.0

4 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago

0.0.0

7 years ago