Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
feat: 'toBeFalse' expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Jun 21, 2017
1 parent db16602 commit 25121e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export function toBeTrue(condition: boolean, errorMessage?: string) {
}
}

/**
* Expect that a condition is false.
* @param condition The condition expected to be false.
* @param errorMessage The optional error message displayed if expectation fails.
* @throws {ExpectationError}
*/
export function toBeFalse(condition: boolean, errorMessage?: string) {
if (condition) {
throw new ExpectationError(errorMessage);
}
}

/**
* Expect that a value exists.
* @param value The value expected to exist.
Expand Down
10 changes: 10 additions & 0 deletions test/Expect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe('expect', () => {
});
});

describe('#toBeFalse', () => {
it('should pass if expectation is fulfilled', () => {
expect.toBeFalse(false);
});

it('should fail if expectation is unfulfilled', () => {
(() => expect.toBeFalse(true, errorMessage)).should.throw(ExpectationError).with.property('message', errorMessage);
});
});

describe('#toExist', () => {
it('should pass if expectation is fulfilled', () => {
expect.toExist(true);
Expand Down

0 comments on commit 25121e6

Please sign in to comment.