-
Notifications
You must be signed in to change notification settings - Fork 85
feat: add react testing library #249
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"test:typecheck": "tsc --noEmit", | ||
"test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.node.ts --rootDir . --silent", | ||
"test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.browser.ts --rootDir . --silent", | ||
"test:unit:react": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../packages/test-config/jest-unit.config.react.ts --rootDir . --silent", | ||
"test:treeshakability:browser": "agadoo dist/index.browser.mjs", | ||
"test:treeshakability:native": "agadoo dist/index.native.mjs", | ||
"test:treeshakability:node": "agadoo dist/index.node.mjs", | ||
|
@@ -63,11 +64,6 @@ | |
"supports bigint and not dead", | ||
"maintained node versions" | ||
], | ||
"devDependencies": { | ||
"@types/react": "^18", | ||
"@types/react-test-renderer": "^18", | ||
"react": "^18" | ||
}, | ||
Comment on lines
-66
to
-70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: i believe we should only be using peer dependencies for react |
||
"dependencies": { | ||
"gill": "workspace:*" | ||
}, | ||
|
@@ -76,6 +72,7 @@ | |
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"react": "^18", | ||
"react-dom": "^18", | ||
"typescript": ">=5" | ||
}, | ||
"engines": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import "@testing-library/jest-dom"; | ||
import { renderHook } from "@testing-library/react"; | ||
import { createSolanaClient } from "gill"; | ||
import { SolanaProvider } from "../providers"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { useSolanaClient } from "../hooks"; | ||
|
||
describe("useSolanaClient", () => { | ||
test("returns solana client from provider", () => { | ||
const client = createSolanaClient({ urlOrMoniker: "mainnet" }); | ||
|
||
const { result } = renderHook(() => useSolanaClient(), { | ||
wrapper: ({ children }) => <SolanaProvider client={client}>{children}</SolanaProvider>, | ||
}); | ||
|
||
expect(result.current).toBe(client); | ||
expect(result.current.rpc).toBeDefined(); | ||
}); | ||
|
||
test("returns fallback devnet client when no provider", () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const { result } = renderHook(() => useSolanaClient(), { | ||
wrapper: ({ children }) => <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>, | ||
}); | ||
|
||
expect(result.current).toBeDefined(); | ||
expect(result.current.rpc).toBeDefined(); | ||
}); | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: i could not find instances of this |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Config } from "jest"; | ||
import path from "path"; | ||
import { createDefaultPreset } from "ts-jest"; | ||
|
||
import commonConfig from "./jest-unit.config.common"; | ||
|
||
const tsJestTransformCfg = createDefaultPreset().transform; | ||
|
||
const config: Config = { | ||
...commonConfig, | ||
displayName: { | ||
color: "grey", | ||
name: "Unit Test (React)", | ||
}, | ||
globals: { | ||
...commonConfig.globals, | ||
__BROWSER__: false, | ||
__NODEJS__: false, | ||
__REACTNATIVE__: false, | ||
}, | ||
setupFilesAfterEnv: [ | ||
...(commonConfig.setupFilesAfterEnv ?? []), | ||
path.resolve(__dirname, "setup-testing-library-jest-dom.ts"), | ||
], | ||
testEnvironment: "jsdom", | ||
testPathIgnorePatterns: [...(commonConfig.testPathIgnorePatterns ?? []), ".browser.ts$", ".node.ts$"], | ||
transform: { | ||
...commonConfig.transform, | ||
...tsJestTransformCfg, | ||
}, | ||
}; | ||
|
||
export default config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "@testing-library/jest-dom"; |
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.
note: i do not think the testing dependencies should be at the root package.json but the existing jest packages are there so continuining this pattern