Skip to content

Commit

Permalink
update token selector test
Browse files Browse the repository at this point in the history
  • Loading branch information
abcrane123 committed Jun 11, 2024
1 parent 79f7aef commit 37cafa2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/token/components/TokenSelectorDropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe('TokenSelectorDropdown', () => {
},
];

beforeEach(() => {
jest.clearAllMocks();
});

it('renders the TokenSelectorDropdown component', () => {
render(<TokenSelectorDropdown setToken={setToken} options={options} onToggle={onToggle} />);

Expand Down Expand Up @@ -57,4 +61,20 @@ describe('TokenSelectorDropdown', () => {
expect(onToggle).toHaveBeenCalled();
});
});

it('does not call onToggle when onToggle is not provided', async () => {
render(<TokenSelectorDropdown setToken={setToken} options={options} />);

await waitFor(() => {
fireEvent.click(screen.getByText(options[0].name));

expect(setToken).toHaveBeenCalledWith(options[0]);
expect(onToggle).not.toHaveBeenCalled();
});

await waitFor(() => {
fireEvent.click(document);
expect(onToggle).not.toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion src/token/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type TokenSearchReact = {
* Note: exported as public Type
*/
export type TokenSelectorReact = {
children: ReactElement<{ onToggle: () => void }>;
children: ReactElement<{ onToggle?: () => void }>;
setToken: (token: Token) => void;
token?: Token;
};
Expand Down

0 comments on commit 37cafa2

Please sign in to comment.