Skip to content

Commit

Permalink
return readonly array on useDatabases hook
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Nov 29, 2023
1 parent d95d0bb commit 8f1d50c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useDatabases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useDatabases.ts
Original file line number Diff line number Diff line change
@@ -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<string[]>([]);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useTables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8f1d50c

Please sign in to comment.