Skip to content

Commit

Permalink
issue streamich#2533 update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geanify committed Feb 19, 2024
1 parent 318eb5d commit 116ae13
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/useCopyToClipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('useCopyToClipboard', () => {
expect(state.error).not.toBeDefined();
});

it('should pass given options to copy to clipboard', () => {
const testValue = 'test';
const testOptions = {
debug: true,
}
let [, copyToClipboard] = hook.result.current;
act(() => copyToClipboard(testValue, testOptions));
[, copyToClipboard] = hook.result.current;

expect(writeText).toBeCalled();
expect(writeText).toBeCalledWith(testValue, testOptions);
});

it('should not call writeText if passed an invalid input and set state', () => {
let testValue = {}; // invalid value
let [state, copyToClipboard] = hook.result.current;
Expand All @@ -67,7 +80,7 @@ describe('useCopyToClipboard', () => {
act(() => copyToClipboard(valueToRaiseMockException));
[state, copyToClipboard] = hook.result.current;

expect(writeText).toBeCalledWith(valueToRaiseMockException);
expect(writeText).toBeCalledWith(valueToRaiseMockException, {});
expect(state.value).toBe(valueToRaiseMockException);
expect(state.noUserInteraction).not.toBeDefined();
expect(state.error).toStrictEqual(new Error(valueToRaiseMockException));
Expand Down

0 comments on commit 116ae13

Please sign in to comment.