UNPKG

assertsjs

Version:

ECMA6 Module for Javascript type validations

34 lines (31 loc) 1.29 kB
jest.unmock('./../../src/Asserts'); describe('Asserts.assertType tests', () => { it('Asserts.assertType should return the value', () => { const Asserts = require('./../../src/Asserts'); const booleanType = 'boolean'; const aBoolean = false; expect(aBoolean).toBe(Asserts.assertType(aBoolean, booleanType)); }); it('Asserts.assertType should return an error', () => { const Asserts = require('./../../src/Asserts'); const stringType = 'string'; const notAString = false; const expectedMessageError = 'Assertion error: ' + stringType + ' must be provided'; try { Asserts.assertType(notAString, stringType); } catch (error) { expect(expectedMessageError).toBe(error.message); } }); it('Asserts.assertType should return an error with wrong type', () => { const Asserts = require('./../../src/Asserts'); const notAString = 1; const aString = false; const expectedMessageError = 'Assertion error: Type must be an string'; try { Asserts.assertType(aString, notAString); } catch (error) { expect(expectedMessageError).toBe(error.message); } }); });