From 6ccc01642b7b106437484618d900749112fa2ca5 Mon Sep 17 00:00:00 2001 From: Bill Dami Date: Tue, 19 Mar 2024 13:54:56 -0400 Subject: [PATCH 1/2] intentionally fail a unit test --- src/components/MaskedSecureInput/MaskedSecureInput.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx b/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx index dfabda2..bcc6d31 100644 --- a/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx +++ b/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx @@ -62,7 +62,7 @@ describe('', () => { await userEvent.type(element, '123456789'); await userEvent.click(screen.getByText('Submit')); expect(onSubmit).toHaveBeenCalledOnce(); - expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ ssn: '123456789' }), expect.anything()); + expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ ssn: '12345678' }), expect.anything()); }); }); }); From adcc00ad91e13a924c113ff816b94bf133524553 Mon Sep 17 00:00:00 2001 From: Bill Dami Date: Tue, 19 Mar 2024 14:04:10 -0400 Subject: [PATCH 2/2] make tests pass again --- src/components/MaskedSecureInput/MaskedSecureInput.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx b/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx index bcc6d31..4d149db 100644 --- a/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx +++ b/src/components/MaskedSecureInput/MaskedSecureInput.test.tsx @@ -9,6 +9,7 @@ import MaskedSecureInput from './MaskedSecureInput'; describe('', () => { it('should render', async () => { render(); + const element = screen.getByLabelText('Label'); expect(element).toBeInTheDocument(); expect(element).toBeVisible(); @@ -16,6 +17,7 @@ describe('', () => { it('should toggle the visiblity of the value when blurred and focused', async () => { render(); + const element = screen.getByLabelText('Label'); await userEvent.type(element, '123456789'); await userEvent.click(document.body); @@ -27,6 +29,7 @@ describe('', () => { it('should output the unformatted value on change', async () => { const onChange = vi.fn(); render(); + const element = screen.getByLabelText('Label'); await userEvent.type(element, '123456789'); expect(element).toHaveValue('123-45-6789'); @@ -58,11 +61,12 @@ describe('', () => { it('should have inter-op with useForm()', async () => { const onSubmit = vi.fn(); render(); + const element = screen.getByLabelText('Label'); await userEvent.type(element, '123456789'); await userEvent.click(screen.getByText('Submit')); expect(onSubmit).toHaveBeenCalledOnce(); - expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ ssn: '12345678' }), expect.anything()); + expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ ssn: '123456789' }), expect.anything()); }); }); });