-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(types): augument global jest * chore: move refactors * chore: remove unused deps * chore: allow mocking with undefined in types * test: set value as undefined
- Loading branch information
Showing
10 changed files
with
131 additions
and
758 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const log = (...args: unknown[]): void => log.default(...args); | ||
// eslint-disable-next-line no-console | ||
log.default = log.warn = (...args: unknown[]): void => console.warn(...args); | ||
|
||
export default log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default { | ||
error: { | ||
invalidSpy: <T>(o: T): string => { | ||
const helpfulValue = `${o ? typeof o : ""}'${o}'`; | ||
return `Cannot spyOn on a primitive value; ${helpfulValue} given.`; | ||
}, | ||
noMethodSpy: <K>(p: K): string => | ||
`Cannot spy on the property '${p}' because it is a function. Please use \`jest.spyOn\`.`, | ||
noUnconfigurableSpy: <K>(p: K): string => | ||
`Cannot spy on the property '${p}' because it is not configurable`, | ||
}, | ||
warn: { | ||
noUndefinedSpy: <K>(p: K): string => | ||
`Spying on an undefined property '${p}'.`, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
"baseUrl": "./src", | ||
}, | ||
"extends": "./tsconfig.json", | ||
"include": ["./src"] | ||
"include": ["./src", "./typings"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Spyable = any; | ||
|
||
export interface MockProp<T = Spyable, K extends keyof T = keyof T> { | ||
mockClear(): void; | ||
mockReset(): void; | ||
mockRestore(): void; | ||
mockValue(v?: T[K]): MockProp<T, K>; | ||
mockValueOnce(v?: T[K]): MockProp<T, K>; | ||
} | ||
|
||
export type SpyMap<T> = Map<T, Map<keyof T, MockProp<T, keyof T>>>; | ||
|
||
export type SpyOnProp = <T>(object: T, propName: keyof T) => MockProp<T>; | ||
|
||
export type IsMockProp = <T, K extends keyof T>( | ||
object: T, | ||
propName: K, | ||
) => boolean; | ||
|
||
declare global { | ||
namespace jest { | ||
const isMockProp: IsMockProp; | ||
const spyOnProp: SpyOnProp; | ||
} | ||
} | ||
|
||
export type ExtendJest = (jestInstance: typeof jest) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters