Skip to content

Commit

Permalink
refactor: Update new tests to match updated testing approach
Browse files Browse the repository at this point in the history
The tests were authored prior to these new practices were established.
  • Loading branch information
dcalhoun committed Sep 14, 2022
1 parent bd255ac commit f804f04
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/data/src/components/use-select/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe( 'useSelect', () => {
registry.registerStore( 'store-2', counterStore );
registry.registerStore( 'store-3', counterStore );

let renderer, childShouldDispatch, setChildShouldDispatch;
let childShouldDispatch, setChildShouldDispatch;
const selectCount1AndDep = jest.fn();

class ChildComponent extends Component {
Expand All @@ -459,9 +459,8 @@ describe( 'useSelect', () => {
}

const TestComponent = jest.fn( () => {
[ childShouldDispatch, setChildShouldDispatch ] = useState(
false
);
[ childShouldDispatch, setChildShouldDispatch ] =
useState( false );
const state = useSelect(
( select ) =>
selectCount1AndDep() || {
Expand All @@ -472,32 +471,28 @@ describe( 'useSelect', () => {

return (
<>
<div data={ state } />
<div role="status">count1:{ state.count1 }</div>
<ChildComponent
childShouldDispatch={ childShouldDispatch }
/>
</>
);
} );

act( () => {
renderer = TestRenderer.create(
<RegistryProvider value={ registry }>
<TestComponent />
</RegistryProvider>
);
} );
const rendered = render(
<RegistryProvider value={ registry }>
<TestComponent />
</RegistryProvider>
);

act( () => {
setChildShouldDispatch( true );
} );

const testInstance = renderer.root;

expect( selectCount1AndDep ).toHaveBeenCalledTimes( 3 );
expect( testInstance.findByType( 'div' ).props.data ).toEqual( {
count1: 1,
} );
expect( rendered.getByRole( 'status' ) ).toHaveTextContent(
'count1:1'
);
} );

it( 'handles registry selectors', () => {
Expand Down

0 comments on commit f804f04

Please sign in to comment.