Skip to content

Commit 3a031b6

Browse files
authored
Type fixes (#774)
* doc: Remove @example JS Doc because it's not part of our JS Doc pattern * fix: Fix some types bugs * ci: Add changeset
1 parent 915c6dd commit 3a031b6

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

.changeset/funny-weeks-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'jest-extended': patch
3+
---
4+
5+
Fix some types bugs

src/matchers/toChange.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Use `.toChange` when checking if a value has changed.
3-
* @example
4-
* expect(() => value--).toChange(() => value);
53
*/
64
export function toChange(mutator: () => unknown | void, checker: () => number) {
75
// @ts-expect-error OK to have implicit any for this.utils

src/matchers/toChangeBy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Use `.toChangeBy` when checking if a value changed by an amount.
3-
* @example
4-
* expect(() => value--).toChangeBy(() => value, -1);
53
*/
64
export function toChangeBy(mutator: () => unknown | void, checker: () => number, by: number = 1) {
75
// @ts-expect-error OK to have implicit any for this.utils

src/matchers/toChangeTo.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Use `.toChangeTo` when checking if a value changed to a specific value.
3-
* @example
4-
* expect(() => Model.deleteAll()).toChangeTo(() => Model.count(), 0);
53
*/
64
export function toChangeTo(mutator: () => unknown | void, checker: () => number, to: number) {
75
// @ts-expect-error OK to have implicit any for this.utils

types/index.d.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ interface CustomMatchers<R> extends Record<string, any> {
6464
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
6565
* @param {Array.<*>} members
6666
*/
67-
toIncludeAllMembers<E = unknown>(members: readonly E[]): R;
67+
toIncludeAllMembers<E = unknown>(members: readonly E[] | E): R;
68+
69+
/**
70+
* Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all the same partial members of a given set.
71+
* @param {Array.<*>} members
72+
*/
73+
toIncludeAllPartialMembers<E = unknown>(members: readonly E[] | E): R;
74+
75+
/**
76+
* Use `.toIncludeSamePartialMembers` when checking if an `Array` contains exactly the same partial members as a given set, in any order
77+
* @param {Array.<*>} members
78+
*/
79+
toIncludeSamePartialMembers<E = unknown>(members: readonly E[]): R;
6880

6981
/**
7082
* Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set.
7183
* @param {Array.<*>} members
7284
*/
73-
toIncludeAnyMembers<E = unknown>(members: readonly E[]): R;
85+
toIncludeAnyMembers<E = unknown>(members: readonly E[] | E): R;
7486

7587
/**
7688
* Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in any order.
@@ -222,6 +234,26 @@ interface CustomMatchers<R> extends Record<string, any> {
222234
*/
223235
toBeObject(): R;
224236

237+
/**
238+
* Use `.toChange` when checking if a value has changed.
239+
* @param {Function} checker
240+
*/
241+
toChange<E = unknown>(checker: () => E): R;
242+
243+
/**
244+
* Use `.toChangeBy` when checking if a value changed by an amount.
245+
* @param {Function} checker
246+
* @param {Number} by
247+
*/
248+
toChangeBy(checker: () => number, by?: number): R;
249+
250+
/**
251+
* Use `.toChangeTo` when checking if a value changed to a specific value.
252+
* @param {Function} checker
253+
* @param {*} to
254+
*/
255+
toChangeTo<E = unknown>(checker: () => E, to: E): R;
256+
225257
/**
226258
* Use `.toContainKey` when checking if an object contains the provided key.
227259
*
@@ -385,7 +417,10 @@ interface CustomMatchers<R> extends Record<string, any> {
385417
* @param {Function} type
386418
* @param {String | RegExp} message
387419
*/
388-
toThrowWithMessage(type: (...args: any[]) => any, message: string | RegExp): R;
420+
toThrowWithMessage(
421+
type: (new (...args: any[]) => { message: string }) | ((...args: any[]) => { message: string }),
422+
message: string | RegExp,
423+
): R;
389424

390425
/**
391426
* Use `.toBeEmptyObject` when checking if a value is an empty `Object`.
@@ -669,24 +704,23 @@ declare namespace jest {
669704

670705
/**
671706
* Use `.toChange` when checking if a value has changed.
672-
* @example
673-
* expect(() => value--).toChange(() => value);
707+
* @param {Function} checker
674708
*/
675709
toChange<E = unknown>(checker: () => E): R;
676710

677711
/**
678-
* Use `.toChangeTo` when checking if a value changed to a specific value.
679-
* @example
680-
* expect(() => Model.deleteAll()).toChangeTo(() => Model.count(), 0);
712+
* Use `.toChangeBy` when checking if a value changed by an amount.
713+
* @param {Function} checker
714+
* @param {Number} by
681715
*/
682-
toChangeTo<E = unknown>(checker: () => E, to: E): R;
716+
toChangeBy(checker: () => number, by?: number): R;
683717

684718
/**
685-
* Use `.toChangeBy` when checking if a value changed by an amount.
686-
* @example
687-
* expect(() => value--).toChangeBy(() => value, -1);
719+
* Use `.toChangeTo` when checking if a value changed to a specific value.
720+
* @param {Function} checker
721+
* @param {*} to
688722
*/
689-
toChangeBy(checker: () => number, by?: number): R;
723+
toChangeTo<E = unknown>(checker: () => E, to: E): R;
690724

691725
/**
692726
* Use `.toContainKey` when checking if an object contains the provided key.
@@ -852,10 +886,7 @@ declare namespace jest {
852886
* @param {String | RegExp} message
853887
*/
854888
toThrowWithMessage(
855-
type:
856-
| (new (...args: any[]) => { message: string })
857-
| (abstract new (...args: any[]) => { message: string })
858-
| ((...args: any[]) => { message: string }),
889+
type: (new (...args: any[]) => { message: string }) | ((...args: any[]) => { message: string }),
859890
message: string | RegExp,
860891
): R;
861892

0 commit comments

Comments
 (0)