Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor: clean up types in jest.setup.ts#4285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jsjoeio merged 1 commit intomainfromjsjoeio/eslint-cleanups
Oct 4, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletionssite/jest.setup.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,16 +38,12 @@ afterAll(() => server.close())
// For now, I limited this to just 'error' - but failing on warnings
// would be a nice next step! We may need to filter out some noise
// from material-ui though.
const CONSOLE_FAIL_TYPES = ["error" /* 'warn' */]
const CONSOLE_FAIL_TYPES = ["error" /* 'warn' */] as const
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Usingas const narrows the type to string literals which is more correct.


// Throw errors when a `console.error` or `console.warn` happens
// by overriding the functions
CONSOLE_FAIL_TYPES.forEach((logType: string) => {
// Suppressing the no-explicit-any to override certain console functions for testing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const consoleAsAny = global.console as any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
consoleAsAny[logType] = (format: string, ...args: any[]): void => {
CONSOLE_FAIL_TYPES.forEach((logType: typeof CONSOLE_FAIL_TYPES[number]) => {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

herelogType is limited to the options we specify inCONSOLE_FAIL_TYPES.

global.console[logType] = <Type>(format: string, ...args: Type[]): void => {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Using the generic, we no longer need to useany.

throw new Error(
`Failing due to console.${logType} while running test!\n\n${util.format(format, ...args)}`,
)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp