Skip to content

Commit

Permalink
Improve useFocusNode test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Jun 17, 2021
1 parent 57016e2 commit 7703ff9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/hooks/use-focus-node.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import React from 'react';
import '@testing-library/jest-dom';
import { render, act } from '@testing-library/react';
import { FocusRoot, FocusNode, useFocusNode, useSetFocus } from '../index';
import {
FocusRoot,
FocusNode,
useFocusNode,
useSetFocus,
useFocusStoreDangerously,
} from '../index';

describe('useFocusNode', () => {
it('returns the expected node', () => {
let setFocus;
let focusNode;
let focusStore;

function TestComponent() {
setFocus = useSetFocus();
focusNode = useFocusNode('nodeA');
focusStore = useFocusStoreDangerously();

return (
<>
Expand All @@ -34,6 +42,8 @@ describe('useFocusNode', () => {
})
);

expect(focusNode).toBe(focusStore.getState().nodes.nodeA);

act(() => setFocus('nodeB'));

expect(focusNode).toEqual(
Expand All @@ -43,5 +53,7 @@ describe('useFocusNode', () => {
isFocusedLeaf: false,
})
);

expect(focusNode).toBe(focusStore.getState().nodes.nodeA);
});
});

0 comments on commit 7703ff9

Please sign in to comment.