Skip to content

Commit

Permalink
test: update test to include empty string as invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverjam committed Jan 17, 2020
1 parent 100b868 commit aaefdf8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/useCopyToClipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('useCopyToClipboard', () => {
});

it('should not call writeText if passed an invalid input and set state', () => {
const testValue = {}; // invalid value
let testValue = {}; // invalid value
let [state, copyToClipboard] = hook.result.current;
act(() => copyToClipboard(testValue));
[state, copyToClipboard] = hook.result.current;
Expand All @@ -51,6 +51,15 @@ describe('useCopyToClipboard', () => {
expect(state.value).toBe(testValue);
expect(state.noUserInteraction).toBe(true);
expect(state.error).toBeDefined();

testValue = ''; // emtpy string is also invalid
act(() => copyToClipboard(testValue));
[state, copyToClipboard] = hook.result.current;
console.log(state);
expect(writeText).not.toBeCalled();
expect(state.value).toBe(testValue);
expect(state.noUserInteraction).toBe(true);
expect(state.error).toBeDefined();
});

it('should catch exception thrown by copy-to-clipboard and set state', () => {
Expand Down

0 comments on commit aaefdf8

Please sign in to comment.