From 8f1d50c08bf7856e985263b5ba131467931c37a4 Mon Sep 17 00:00:00 2001 From: Spencer Torres Date: Wed, 29 Nov 2023 10:24:26 -0500 Subject: [PATCH] return readonly array on useDatabases hook --- src/hooks/useDatabases.test.ts | 4 ++-- src/hooks/useDatabases.ts | 2 +- src/hooks/useTables.test.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hooks/useDatabases.test.ts b/src/hooks/useDatabases.test.ts index fc18c7d4..22c0168a 100644 --- a/src/hooks/useDatabases.test.ts +++ b/src/hooks/useDatabases.test.ts @@ -5,7 +5,7 @@ import useDatabases from './useDatabases'; describe('useDatabases', () => { it('should return empty array if invalid datasource is provided', async () => { - let result: { current: string[] }; + let result: { current: readonly string[] }; await act(async () => { const r = renderHook(() => useDatabases(undefined!)); result = r.result; @@ -18,7 +18,7 @@ describe('useDatabases', () => { const mockDs = {} as Datasource; mockDs.fetchDatabases = jest.fn(() => Promise.resolve(['a', 'b'])); - let result: { current: string[] }; + let result: { current: readonly string[] }; await act(async () => { const r = renderHook(() => useDatabases(mockDs)); result = r.result; diff --git a/src/hooks/useDatabases.ts b/src/hooks/useDatabases.ts index 2af17965..5d2af5c1 100644 --- a/src/hooks/useDatabases.ts +++ b/src/hooks/useDatabases.ts @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react'; import { Datasource } from 'data/CHDatasource'; -export default (datasource: Datasource): string[] => { +export default (datasource: Datasource): readonly string[] => { const [databases, setDatabases] = useState([]); useEffect(() => { diff --git a/src/hooks/useTables.test.ts b/src/hooks/useTables.test.ts index 51ea182e..f3fc4665 100644 --- a/src/hooks/useTables.test.ts +++ b/src/hooks/useTables.test.ts @@ -5,7 +5,7 @@ import useTables from './useTables'; describe('useTables', () => { it('should return empty array if invalid datasource is provided', async () => { - let result: { current: string[] }; + let result: { current: readonly string[] }; await act(async () => { const r = renderHook(() => useTables(undefined!, 'db')); result = r.result; @@ -18,7 +18,7 @@ describe('useTables', () => { const mockDs = {} as Datasource; mockDs.fetchTables = jest.fn((db: string) => Promise.resolve(['a', 'b'])); - let result: { current: string[] }; + let result: { current: readonly string[] }; await act(async () => { const r = renderHook(() => useTables(mockDs, '')); result = r.result; @@ -31,7 +31,7 @@ describe('useTables', () => { const mockDs = {} as Datasource; mockDs.fetchTables = jest.fn((db: string) => Promise.resolve(['a', 'b'])); - let result: { current: string[] }; + let result: { current: readonly string[] }; await act(async () => { const r = renderHook(() => useTables(mockDs, 'db')); result = r.result;