-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: utilities for unit testing components (#23)
* test: add utils * test: typecheck tests * test: clean type coercions * test: add @testing-library/user-event
- Loading branch information
Showing
11 changed files
with
119 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { i18n } from '@lingui/core' | ||
import { I18nProvider } from '@lingui/react' | ||
import { render as baseRender, RenderOptions, RenderResult } from '@testing-library/react' | ||
import { dynamicActivate } from 'i18n' | ||
import fetch from 'jest-fetch-mock' | ||
import { Provider as AtomProvider } from 'jotai' | ||
import { PropsWithChildren, ReactElement } from 'react' | ||
import { ThemeProvider } from 'theme' | ||
|
||
export type { RenderResult } from '@testing-library/react' | ||
export { act } from '@testing-library/react' | ||
export { default as user } from '@testing-library/user-event' | ||
export { default as fetch } from 'jest-fetch-mock' | ||
|
||
fetch.enableMocks() | ||
|
||
beforeAll(async () => { | ||
await dynamicActivate('en-US') | ||
}) | ||
|
||
function TestProvider({ children }: PropsWithChildren<unknown>) { | ||
return ( | ||
<ThemeProvider> | ||
<I18nProvider i18n={i18n}> | ||
<AtomProvider>{children}</AtomProvider> | ||
</I18nProvider> | ||
</ThemeProvider> | ||
) | ||
} | ||
|
||
export function render(ui: ReactElement, options?: RenderOptions): RenderResult { | ||
const result = baseRender(<TestProvider>{ui}</TestProvider>, options) | ||
|
||
const rerender = result.rerender | ||
result.rerender = function (this, ui) { | ||
return rerender.call(this, <TestProvider>{ui}</TestProvider>) | ||
} | ||
|
||
return result | ||
} |
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
import fetchMock from 'jest-fetch-mock' | ||
import { TextDecoder, TextEncoder } from 'util' | ||
|
||
fetchMock.enableMocks() | ||
|
||
global.TextDecoder = TextDecoder | ||
global.TextEncoder = TextEncoder |
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,32 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"alwaysStrict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"baseUrl": "src", | ||
"declaration": true, | ||
"declarationDir": "dts", | ||
"downlevelIteration": true, | ||
"emitDeclarationOnly": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"jsx": "react-jsx", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": false, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"target": "es5", | ||
"useUnknownInCatchVariables": false | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["src/**/*.d.ts", "src/index.tsx"] | ||
} |
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
3aaf1f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
widgets – ./
widgets-uniswap.vercel.app
widgets-seven-tau.vercel.app
widgets-git-main-uniswap.vercel.app