-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
186 additions
and
37 deletions.
There are no files selected for viewing
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 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 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { makeUniqueId } from "../common/makeUniqueId"; | ||
|
||
export function stringifyForDisplay(value: any): string { | ||
const undefId = makeUniqueId("stringifyForDisplay"); | ||
return JSON.stringify(value, (key, value) => { | ||
return value === void 0 ? undefId : value; | ||
}).split(JSON.stringify(undefId)).join("<undefined>"); | ||
} |
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,49 @@ | ||
function wrapTestFunction( | ||
fn: (...args: any[]) => any, | ||
consoleMethodName: "log" | "warn" | "error", | ||
) { | ||
return function () { | ||
const args = arguments; | ||
const spy = jest.spyOn(console, consoleMethodName); | ||
spy.mockImplementation(() => {}); | ||
return new Promise(resolve => { | ||
resolve(fn?.apply(this, args)); | ||
}).finally(() => { | ||
expect(spy).toMatchSnapshot(); | ||
spy.mockReset(); | ||
}); | ||
}; | ||
} | ||
|
||
export function withErrorSpy< | ||
TArgs extends any[], | ||
TResult, | ||
>( | ||
it: (...args: TArgs) => TResult, | ||
...args: TArgs | ||
) { | ||
args[1] = wrapTestFunction(args[1], "error"); | ||
return it(...args); | ||
} | ||
|
||
export function withWarningSpy< | ||
TArgs extends any[], | ||
TResult, | ||
>( | ||
it: (...args: TArgs) => TResult, | ||
...args: TArgs | ||
) { | ||
args[1] = wrapTestFunction(args[1], "warn"); | ||
return it(...args); | ||
} | ||
|
||
export function withLogSpy< | ||
TArgs extends any[], | ||
TResult, | ||
>( | ||
it: (...args: TArgs) => TResult, | ||
...args: TArgs | ||
) { | ||
args[1] = wrapTestFunction(args[1], "log"); | ||
return it(...args); | ||
} |
This file was deleted.
Oops, something went wrong.