From a7d2639a732f96ee5533ceece2e532fca9f6fc57 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Mon, 4 Dec 2023 09:53:31 +0000 Subject: [PATCH] fix: unit tests --- .../dapp-kit-react/src/provider/ThemeProvider.tsx | 12 +++++------- .../test/helpers/react-test-helpers.tsx | 11 +++++++---- .../test/provider/ThemeProvider.test.tsx | 13 ++++++++----- .../src/components/connect-button-with-modal.ts | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/dapp-kit-react/src/provider/ThemeProvider.tsx b/packages/dapp-kit-react/src/provider/ThemeProvider.tsx index 1a95915b..0507f11d 100644 --- a/packages/dapp-kit-react/src/provider/ThemeProvider.tsx +++ b/packages/dapp-kit-react/src/provider/ThemeProvider.tsx @@ -9,7 +9,7 @@ interface Theme { mode: ThemeMode; } -interface ContextProperties { +interface ThemeContextProperties { theme: Theme; toggleTheme: () => void; } @@ -18,11 +18,9 @@ const defaultTheme: Theme = { mode: 'LIGHT', }; -const ThemeContext = createContext({ - theme: defaultTheme, - // eslint-disable-next-line @typescript-eslint/no-empty-function - toggleTheme: () => {}, -}); +const ThemeContext = createContext( + undefined, +); const ThemeProvider = ({ children }: { children: ReactNode }) => { const [currentTheme, setCurrentTheme] = useState(defaultTheme); @@ -46,4 +44,4 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => { ); }; -export { ThemeProvider, ThemeContext }; +export { ThemeProvider, ThemeContext, type ThemeContextProperties }; diff --git a/packages/dapp-kit-react/test/helpers/react-test-helpers.tsx b/packages/dapp-kit-react/test/helpers/react-test-helpers.tsx index 809c34b3..7425dafb 100644 --- a/packages/dapp-kit-react/test/helpers/react-test-helpers.tsx +++ b/packages/dapp-kit-react/test/helpers/react-test-helpers.tsx @@ -4,12 +4,15 @@ import { DAppKitProvider, SelectWalletModal, } from '../../src'; +import { ThemeProvider } from '../../src/provider/ThemeProvider'; export const wrapper = ({ children }: { children?: React.ReactNode }) => ( - {children} - - - + + {children} + + + + ); diff --git a/packages/dapp-kit-react/test/provider/ThemeProvider.test.tsx b/packages/dapp-kit-react/test/provider/ThemeProvider.test.tsx index 6205e132..12372eb4 100644 --- a/packages/dapp-kit-react/test/provider/ThemeProvider.test.tsx +++ b/packages/dapp-kit-react/test/provider/ThemeProvider.test.tsx @@ -12,12 +12,15 @@ describe('useThemeContext', () => { expect(result.current).toBeDefined(); - expect(result.current.theme).toEqual({ mode: 'LIGHT' }); + expect(result.current?.theme).toEqual({ mode: 'LIGHT' }); - result.current.toggleTheme(); + result.current?.toggleTheme(); - await waitFor(() => { - expect(result.current.theme).toEqual({ mode: 'DARK' }); - }); + await waitFor( + () => { + expect(result.current?.theme).toEqual({ mode: 'DARK' }); + }, + { timeout: 3000 }, + ); }); }); diff --git a/packages/dapp-kit-ui/src/components/connect-button-with-modal.ts b/packages/dapp-kit-ui/src/components/connect-button-with-modal.ts index 75de14ec..7d2d872a 100644 --- a/packages/dapp-kit-ui/src/components/connect-button-with-modal.ts +++ b/packages/dapp-kit-ui/src/components/connect-button-with-modal.ts @@ -83,7 +83,7 @@ export class ConnectButtonWithModal extends LitElement { } private handleOpen = (): void => { - this.open = false; + this.open = true; DAppKitUI.wallet.disconnect(); this.requestUpdate(); };