kephalosk
@kephaloskAll solutions
Frontend Quiz using React/TypeScript/Jest/Redux/SCSS
#jest#react#redux#typescript#sass/scssPSubmitted about 2 months agoRecommended scale-factors for clamp function. I allways have to set down the given font-sizes to prevent oversized fonts.
Password Generator using Best Practices in React/TypeScript/Jest/Redux
#jest#react#redux#sass/scss#typescriptPSubmitted 2 months agoI want to know how to test an Error that is thrown in an async hook in jest.
I tried this and the error is thrown succesfully, but act() did not pass the error to expect(), so the test fails:
it("throws an error if copy to clipboard fails", async (): setup({ password: "testPassword" }); const element: HTMLElement = screen.getByTestId(testComponentDataTestId); expect( async () => await act(async () => { fireEvent.click(element); }), ).toThrow(new Error(ERROR_MESSAGE_PASSWORD_COPY_PREFIX)); });
As a workaround I changed that Error to a console.error, so I could spy on it and check if it was called. So this works, but I would prefer to throw an error at this point:
it("throws an error if copy to clipboard fails", async (): Promise<void> => { setup({ password: "testPassword" }); const element: HTMLElement = screen.getByTestId(testComponentDataTestId); await act(async (): Promise<void> => { fireEvent.click(element); }); expect(console.error).toHaveBeenCalledTimes(1); expect(console.error).toHaveBeenCalledWith( ERROR_MESSAGE_PASSWORD_COPY_PREFIX + errorMessage, );
Thanks for any help. :)
Tip calculator app using React/Redux/Jest/Vite/SWC
#jest#react#redux#vite#typescriptPSubmitted 3 months agon.a.