-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #1280
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { ApiContext } from '@deephaven/jsapi-bootstrap'; | ||
import dh from '@deephaven/jsapi-shim'; | ||
import { TableUtils } from '@deephaven/jsapi-utils'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useTableUtils from './useTableUtils'; | ||
|
||
const wrapper = ({ children }) => ( | ||
<ApiContext.Provider value={dh}>{children}</ApiContext.Provider> | ||
); | ||
|
||
it('should return a TableUtils instance based on the current dh api context', () => { | ||
const { result } = renderHook(() => useTableUtils(), { wrapper }); | ||
expect(result.current.dh).toBe(dh); | ||
expect(result.current).toBeInstanceOf(TableUtils); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useMemo } from 'react'; | ||
import { useApi } from '@deephaven/jsapi-bootstrap'; | ||
import { TableUtils } from '@deephaven/jsapi-utils'; | ||
|
||
/** | ||
* Get a `TableUtils` instance using `dh` api from the current context. | ||
*/ | ||
export default function useTableUtils(): TableUtils { | ||
const dh = useApi(); | ||
return useMemo(() => new TableUtils(dh), [dh]); | ||
} |