From 206917e4ace2abf2edfa054850cbabcd4e872bac Mon Sep 17 00:00:00 2001 From: JanMalch <25508038+JanMalch@users.noreply.github.com> Date: Thu, 22 Oct 2020 17:02:52 +0200 Subject: [PATCH] test: fix expected message --- README.md | 2 +- index.test.ts | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2a4697f..0e279bd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You can now import the following functions `from 'ts-code-contracts'`: - [`useIf` for assignments](#useif) Make sure to read the `@example`s in the documentation below -or refer to the [test cases](https://github.com/JanMalch/ts-code-contracts/blob/master/index.test.ts#L175-L205) +or refer to the [test cases](https://github.com/JanMalch/ts-code-contracts/blob/master/index.test.ts#L166-L196) and [typing assistance](https://github.com/JanMalch/ts-code-contracts/blob/master/index.test-d.ts#L54-L65)! ## Contracts diff --git a/index.test.ts b/index.test.ts index 407a952..cd09f8a 100644 --- a/index.test.ts +++ b/index.test.ts @@ -50,8 +50,7 @@ describe('contracts', () => { describe('NonNullish contracts', () => { const contractTest = ( contract: (value: T, message?: string) => NonNullable, - errorType: new (...args: any[]) => Error, - defaultMessage: string + errorType: new (...args: any[]) => Error ): void => { describe(contract.name, () => { it('should not error if the value is defined', () => { @@ -60,23 +59,15 @@ describe('NonNullish contracts', () => { it('should throw an Error if the value is not defined', () => { expect(() => contract(null)).toThrowError( // eslint-disable-next-line new-cap - new errorType(defaultMessage) + new errorType('Value must not be null or undefined') ); }); }); }; - contractTest( - requiresNonNullish, - PreconditionError, - 'Value must be defined' - ); - contractTest( - checksNonNullish, - IllegalStateError, - 'Callee invariant violation' - ); - contractTest(ensuresNonNullish, PostconditionError, 'Unmet postcondition'); + contractTest(requiresNonNullish, PreconditionError); + contractTest(checksNonNullish, IllegalStateError); + contractTest(ensuresNonNullish, PostconditionError); }); describe('utils', () => {