There are many alternatives, sometimes is not a free choice (work, consolidated projects, etc).
But what do you prefer to use and how do you choose it?
Personal and work examples are welcome.
There are many alternatives, sometimes is not a free choice (work, consolidated projects, etc).
But what do you prefer to use and how do you choose it?
Personal and work examples are welcome.
For further actions, you may consider blocking this person and/or reporting abuse
Sukhpinder Singh -
RemoteWLB -
Sukhpinder Singh -
Syakir -
Top comments (7)
Tape.js for util libs
It's super easy to setup and use. Doesn't require plugins so it can be run w/o install via npx.
Jest for DOM interactions
Same reasons I use Tape except whrn I need to test some fake DOM interactions.
testing-library for framework code
Lightweight, doesn't depend on framework-specific implementation details. Just add a test-id and use it to check on an element's state.
Cypress.io for E2E/Integration*
B/C Selenium is a non-deterministic piece of trash. Puppeteer would probably work as well.
Yes, yes and 1000 times yes. By far the most sensible option 90% of the time for unit testing some JS. Small surface area (barely any dependencies), runs quickly, sensible set of default assertions built in. Very much in the style of the Go testing library - you can extend it yourself by writing your own functions.
If you're looking for clean, easy to read tests that don't install half of npm to your computer, this is my go to lib.
Keep in mind, these choices are opinionated. IMO, the best testing framework is the one you notice the least.
Wherever possible, I stay away from FWs that are overloaded with a ton of convenience features or support trendy-but-not-useful approaches (ex BDD).
For example Mocha/Chai is usually the most popular for unit tests. I'm not a fan.
Protractor (Angular) and Enzyme (React) work perfectly well for framework-specific testing. But, I like that testing-library works directly on the DOM.
I like Tape b/c it doesn't use a plugin model for formatting the output. Instead, it outputs TAP (Test Again Protocol).
TAP is really basic and not too readable but since it's a standard there are plenty of tools built to consume it. For example piping tap into tap-spec will give you nice looking colorized test results.
Where TAP really makes a difference is CI/CD testing. On CI/CD speed trumps readability.
IMO, every testing lib should support TAP. If not as the default, then as an option.
Why the strong dislike of Selenium? I've used it before. Work that should've taken a week took almost a month b/c tests would randomly fail. To compensate, the tests became riddled with wait statements and other hacks.
Non-deterministic testing is a nightmare scenario for a Dev. It's really aggravating, time consuming, and makes you look bad even if you're doubled-down on effort trying to make it work.
Selenium is the anti-thesis of "the best testing FW is the one you notice least" in every way.
Here you addressed a good amount of my doubts and curiosities. Greatly appreciated :)
Wow, these are helpful suggestions. I am reading a few comparison/opinionated articles, but takes me a
while
to wrap my mind around this topic :)Lots of good discussion here, specifically around end-to-end testing....
Cypress vs.....
Ben Halpern ・ Oct 21 '19 ・ 1 min read
At DEV we also use Jest for testing. It wasn't an overly controversial choice as it was just fairly popular, but other folks on the team might be able to speak more to that.
Yes, I did a search before to post. Actually lots :)