Skip to content

Commit

Permalink
fix: type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kark committed Jan 9, 2025
1 parent 2602147 commit 7079a2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('creating routes', () => {
describe('getUrl', () => {
it('should compute URL path', () => {
const { result } = hooks.renderHook(() => useRoutes());
const routes = result.current;
const routes = result.current as ReturnType<typeof useRoutes>;

expect(routes).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -51,15 +51,15 @@ describe('creating routes', () => {
});
it('throws when required params are missing', () => {
const { result } = hooks.renderHook(() => useRoutes());
const routes = result.current;
const routes = result.current as ReturnType<typeof useRoutes>;

expect(() => routes.heroDetail.getUrl()).toThrow();
});
});
describe('go', () => {
it('should redirect to another route', () => {
const { result, history } = hooks.renderHook(() => useRoutes());
const routes = result.current;
const routes = result.current as ReturnType<typeof useRoutes>;

expect(history.location.pathname).toMatchInlineSnapshot(
`"/test-with-big-data/random-entry-point"`
Expand All @@ -81,7 +81,7 @@ describe('creating routes', () => {
});
it('throws when required params are missing', () => {
const { result } = hooks.renderHook(() => useRoutes());
const routes = result.current;
const routes = result.current as ReturnType<typeof useRoutes>;

expect(() => routes.heroDetail.go()).toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const errorLoadingLocalesMock = jest.fn(() =>
describe('loading data', () => {
it('should load data via hook', async () => {
const useL10n = createL10NHook<Candies>(loadLocalesMock);
const { result } = renderHook<unknown, Result>(() => useL10n('en'));
const { result } = renderHook<
{ isLoading: boolean; data: unknown; error?: unknown },
Result
>(() => useL10n('en'));
expect(result.current.isLoading).toBe(true);
expect(result.current.data).toEqual({});
expect(result.current.error).not.toBeDefined();
Expand All @@ -48,7 +51,10 @@ describe('loading data', () => {
describe('error loading data', () => {
it('should return error and report error to sentry', async () => {
const useL10n = createL10NHook<Candies>(errorLoadingLocalesMock);
const { result } = renderHook<unknown, Result>(() => useL10n('en'));
const { result } = renderHook<
{ isLoading: boolean; data: unknown; error?: unknown },
Result
>(() => useL10n('en'));
expect(result.current.isLoading).toBe(true);
expect(result.current.data).toEqual({});
expect(result.current.error).not.toBeDefined();
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/components/sdk-get/sdk-get.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('rendering', () => {
dispatch={() => Promise.resolve({ status: 'ok' })}
render={({ isLoading, result, error }) => {
if (isLoading) return <div>Loading ...</div>;
/* @ts-ignore */
if (error) return <div>Error: {error}</div>;
return <div>{JSON.stringify(result)}</div>;
}}
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('rendering and refetching', () => {
dispatch={() => Promise.resolve({ count })}
render={({ isLoading, result, error, refresh }) => {
if (isLoading) return <div>Loading ...</div>;
/* @ts-ignore */
if (error) return <div>Error: {error}</div>;
return (
<div>
Expand Down

0 comments on commit 7079a2b

Please sign in to comment.