Skip to content

Commit

Permalink
test: fix expected message
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMalch committed Oct 22, 2020
1 parent 6c166b7 commit 206917e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 5 additions & 14 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ describe('contracts', () => {
describe('NonNullish contracts', () => {
const contractTest = (
contract: <T>(value: T, message?: string) => NonNullable<T>,
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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 206917e

Please sign in to comment.