Testing hell 😱. Honest question. How do you survive? What's your secret?
OpenSource

OpenSource @opensourcee

About: Let's build together

Joined:
Sep 17, 2023

Testing hell 😱. Honest question. How do you survive? What's your secret?

Publish Date: Oct 18 '24
20 22

We've just spent the worst couple of hours trying to work with Jest with SVG, nanoid, ... Anything that's slightly out of the ordinary Jest won't work and we found out we were spending more time debugging Jest than debugging our code. So... please help us. How do you survive the testing hell??

Comments 22 total

  • Ben Halpern
    Ben HalpernOct 18, 2024

    If You're Going Through Hell, Keep Going

    - Winston Churchill

    Does that help you? 🙃

    • OpenSource
      OpenSourceOct 18, 2024

      Lol. I'm more tempted of turning around and never testing again!

      • Valery Zinchenko
        Valery ZinchenkoOct 29, 2024

        As for everything, it's first difficult and tempting to quit, but then it suddenly just becomes a new normality for you and it's not difficult anymore, maybe you even start to like it.

  • Best Codes
    Best CodesOct 18, 2024

    What languages are you writing and testing in? I've used Jest (barely). Have you tried anything besides Jest? I might have to play around with this...

    • OpenSource
      OpenSourceOct 18, 2024

      We're using React. Tried Cypress and the experience is 10000x better. But Cypress is more e2e. I was looking for a unit test and integration test library. Jest is by far one of the most recommended. I really don't know how. It's a pain...

  • Gregory Gaines
    Gregory GainesOct 18, 2024

    Testing that's slowing you down is better than writing code with no tests and moving fast.

    10/10 times

  • Jon Randy 🎖️
    Jon Randy 🎖️Oct 19, 2024

    Barely used any automated testing in 30 years... and it's never been a problem.

  • Musab
    MusabOct 19, 2024

    Simple, just don't write tests.

  • FalkZ
    FalkZOct 19, 2024

    Have you tried vitest (vitest.dev/)?
    IMO the easiest and fastest way to do unit tests :). But if your trying to do sth. very niche, there might only support for it in jest…

  • Alex Lohr
    Alex LohrOct 19, 2024

    Check out testing-library, stop testing implementation details like SVGs, maybe really consider switching to vitest.

  • Daniel Hillmann
    Daniel HillmannOct 19, 2024

    Is there any chance that maybe you are holding it wrong? Try opening a stackoverflow ticket! Personally I have had mostly joy of Jest and not framework specific issues. For my use cases there have been great documentation as well as community posts about all the questions I have been looking for. Mostly, at least.

  • Oscar
    OscarOct 19, 2024

    Frontend testing is... yeah, I understand your pain. I try and make it a habit and do it consistently, so I'm not having to write a whole bunch of tests all at once. But still, I have an entire file that isn't tested because MSW and Vitest simply refuse to cooperate with each other :p

    • OpenSource
      OpenSourceOct 24, 2024

      Tell me about it... I think we've found our one file like that.

  • CodeWithCaen
    CodeWithCaenOct 19, 2024

    Frontend testing can be hard; but oftentimes when you're having issues writing tests, it's because something is wrong with your code. Poorly designed architectures are hard to test, especially when they stray from the conventions the testing frameworks are designed for.

  • Valeria
    ValeriaOct 20, 2024

    Covering existing code with tests is usually a nightmare, try doing it the other way around next time (when you’re refactoring or fixing a bug). Testing shouldn’t hurt that much, even with Jest.

    Try to split your components into “dumb” view layer and “logic” functions, they should be easy to test:

    • Come up with a type or interface that is elegant and does exactly what’s needed ( i.e. describe function arguments)
    • Write mock data / test cases ( i.e. input/output pairs following the structure you defined)

    The next in the line would be “component” tests, that would check the component that connects your many small functions together:

    • Try testing-library, as mentioned, with it you can write a11y driven tests, I.e. select elements based on their roles and titles like a person with a screen reader would
    • If you’re struggling with mocking complex functionality try msw (mock server worker) that lets you easily mock any api request
    • Consider using Storybook or similar if you need visual testing, you don’t need to incorporate automated visual regression tests unless you have to, but you would be able to make manual testing easier

    With that said, not everything is worth automating, no automated tests is sometimes better than flaky tests and tests that are breaking on every code change. But some good tests are always better than none, so just try and find the best value for the time spent.

  • chris407x
    chris407xOct 20, 2024

    For testing to work and scale well, you must have a test-driven development process from the beginning.

    TDD code will work differently than freeform jazz odyssey code. You and your team need to be on board, and management needs to support this. It is very common to have code that works, but is difficult to test. It is helpful to have somebody with deep experience in testing to help out and train your developers.

    I have worked at my employer for eight years, and I must say that the payoff in clarity for TDD is real. However, the benefit is often years away.

    A feature is written and it works, whether the code is TDD or not. Can your team write TDD at the same speed as untested code? With practice you can, but it is not easy.

    If you are working on something like a public API or banking software, a unit test would be very important because other people expect consistency and the cost of bugs/errors is high.

    You might want to consider partial coverage: test your transaction code thoroughly, but don't test buttons or layout.

  • Bryant Vidal
    Bryant VidalOct 23, 2024

    Great read on surviving the challenges of testing in software development! It really highlights how critical testing is for ensuring quality. This reminds me of the online casino industry, like casino Zodiac , where rigorous testing is essential to maintain fair play and user satisfaction. Just as developers share tips for effective testing, casinos must constantly refine their systems to provide a seamless gaming experience. Ensuring reliability and security in both fields is key to building trust with users.

  • Martin Baun
    Martin BaunOct 23, 2024

    If you use SQLite or your queries are generic SQL, you should switch to using SQLite under in-memory mode for your DB driver during testing. It's extremely fast to bring up and tear down an SQLite DB. You don't need to deal with setting file paths, and you can have multiple SQLite DB instances open. Cleaning up is easy since it's in memory.

  • Prartha
    Prartha Oct 23, 2024

    I can’t recommend EchoAPI enough! It’s an all-in-one tool that meets all my API testing needs and integrates flawlessly into my development environment.

  • Maksim Zaikov
    Maksim ZaikovDec 30, 2024

    Unfortunately sometimes you need to write something like backdoor to test the frontend code. It's may be very dangerous for production ENV, but you will need to make it workable only for local ENV, running only on localhost and in this case your code will be safe and secure.

Add comment