Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 3 months ago

Password Generator using Best Practices in React/TypeScript/Jest/Redux

jest, react, redux, sass/scss, typescript
P
kephalosk•400
@kephalosk
A solution to the Password generator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

Using Single Responsibility Principle. At least for all UI-components (atoms and containers). In case of some custom hooks I'm not sure.

What challenges did you encounter, and how did you overcome them?

Building a custom SliderBar. I never did that before. I programmed it step by step: first Layout (background,value,adjuster,container); than user interaction(Click,KeyDown,KeyUp,MouseDown,MouseMove,MouseUp); after that storage logic.

What specific areas of your project would you like help with?

I 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. :)

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Emmanuel Lopez•530
    @EmLopezDev
    Posted 2 months ago

    Wow this is great, I love the approach with making every part of the app re-usable including the footer. Adding testing is also such a good touch, I am not too familiar with testing so I can't give you the testing feedback you are looking for. All I can say I am impressed with it all.

    Some take aways from my perspective:

    • Although the re-usability and abstraction is a great approach and maybe you were just practicing it or getting into the habit but I personally think this solution is overly abstracted and could have been a bit more simple. With the inception of files and components it does take a while to follow and put it all together during review. But again that is just my point of view, not saying what you did was wrong but a simpler approach for a simple challenge would make it easier to maintain, easier to test, and easier to debug. Just something to keep in mind.
    • Aside from that the look of the app is a bit off from the design, some of the padding is off like around the button and body. Also the color of the text when the password is generated is incorrect.
    Marked as helpful

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub