Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvail committed Mar 15, 2023
1 parent 477bab4 commit d181a49
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ui/apps/platform/src/hooks/useSet.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import { renderHook, act } from '@testing-library/react-hooks';
import useSet from './useSet';

test('useSet should correctly toggle items', () => {
test('useSet should accept a starting set', () => {
// Membership is based on reference equality
const objA = { test: 'test' };
const objB = { test: 'test' };

const { result } = renderHook(() => {
const set = useSet(new Set([objA]));
return set;
});

expect(result.current.has(objA)).toBeTruthy();
expect(result.current.has(objB)).toBeFalsy();

act(() => {
result.current.toggle(objA);
result.current.toggle(objB);
});

expect(result.current.has(objA)).toBeFalsy();
expect(result.current.has(objB)).toBeTruthy();
});

test('useSet should correctly toggle items and report their membership', () => {
const { result } = renderHook(() => {
const set = useSet<string>();
return set;
Expand Down

0 comments on commit d181a49

Please sign in to comment.