Skip to content

Commit

Permalink
Applies notes from code review: improves typescript types and asserts…
Browse files Browse the repository at this point in the history
… support for non-numeric values
  • Loading branch information
MrLeebo committed Nov 17, 2022
1 parent a844e82 commit 0841424
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/matchers/toChangeTo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ describe('.toChangeTo', () => {
}).toChangeTo(() => counter.count(), 0),
).toThrowErrorMatchingSnapshot();
});

test('passes when given a non-numeric value', () => {
let special = 'spicy chicken sandwich';
expect(() => {
special = 'meatloaf';
}).toChangeTo(() => special, 'meatloaf');
});
});

describe('.not.toChange', () => {
Expand Down
25 changes: 23 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ declare namespace jest {
* @example
* expect(() => value--).toChange(() => value);
*/
toChange(checker: () => number): R;
toChange<E = unknown>(checker: () => E): R;

/**
* Use `.toChangeTo` when checking if a value changed to a specific value.
* @example
* expect(() => Model.deleteAll()).toChangeTo(() => Model.count(), 0);
*/
toChangeTo<Val>(checker: () => Val, to?: Val): R;
toChangeTo<E = unknown>(checker: () => E, to: E): R;

/**
* Use `.toChangeBy` when checking if a value changed by an amount.
Expand Down Expand Up @@ -675,6 +675,27 @@ declare namespace jest {
*/
toBeObject(): any;

/**
* Use `.toChange` when checking if a value has changed.
* @example
* expect(() => value--).toChange(() => value);
*/
toChange<E = unknown>(checker: () => E): any;

/**
* Use `.toChangeTo` when checking if a value changed to a specific value.
* @example
* expect(() => Model.deleteAll()).toChangeTo(() => Model.count(), 0);
*/
toChangeTo<E = unknown>(checker: () => E, to?: E): any;

/**
* Use `.toChangeBy` when checking if a value changed by an amount.
* @example
* expect(() => value--).toChangeBy(() => value, -1);
*/
toChangeBy(checker: () => number, by?: number): any;

/**
* Use `.toContainKey` when checking if an object contains the provided key.
*
Expand Down

0 comments on commit 0841424

Please sign in to comment.