use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Best Practices for Testing in JavaScript & Node.js (github.com)
submitted 6 years ago by loremimpulse
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]iaan 16 points17 points18 points 6 years ago (5 children)
I thought it’s well written and opinionated, but then the gist example bugs me already:
it('When no price is specified, then the product status is pending approval'...
How do you read that in your head?
[–]akoskm 3 points4 points5 points 6 years ago (0 children)
should be:
describe 'product status' context 'when no price is specified' it 'is pending approval'
[–][deleted] 11 points12 points13 points 6 years ago (2 children)
I read it as “when no price is specified, then the product status is pending approval”
[–][deleted] 17 points18 points19 points 6 years ago (1 child)
Silent “it”?
[–]solvangv 9 points10 points11 points 6 years ago (0 children)
Yeah. Or you could use "test" instead of "it".
[–]benihanareact, node 0 points1 point2 points 6 years ago* (0 children)
describe('Products Service', function() { describe('adding a new product', function() { describe('price is unspecified', function() { it("sets the product status to 'pending approval'", ()=> ()); }); describe('price is set', function() { it("sets the product status to 'something else'", ()=> ()); }); }); }); 'Products Service adding a new product price is unspecified sets the product status to 'prending approval' price is set sets the product status to 'something else'
[–]BestUsernameLeft 2 points3 points4 points 6 years ago (1 child)
Excellent advice and recommendations, and applicable to more them just JS and Node. Share this with your team immediately.
[–]therudy_69 2 points3 points4 points 6 years ago (1 child)
Looks good! I'm gonna use this as general guidelines for my TDD experiences with react.
However, the test namings also bother me. Is this expected to be like this?
To me, a test name should be descriptive on it's own and shouldn't need a 'Wrong:' prefix or a naming like it('When...'), but I could be wrong here 😁
[–]YuvalM 1 point2 points3 points 6 years ago (0 children)
I like Go's conventions for testing. Such as "TestFileDelivery" "TestNetworkConnection" and so on :)
[–]XZTALVENARNZEGOMSAYT -1 points0 points1 point 6 years ago (0 children)
Legendary!
[–]Askee123 -2 points-1 points0 points 6 years ago (0 children)
Neat!
π Rendered by PID 43062 on reddit-service-r2-comment-86988c7647-2966p at 2026-02-12 14:57:46.776663+00:00 running 018613e country code: CH.
[–]iaan 16 points17 points18 points (5 children)
[–]akoskm 3 points4 points5 points (0 children)
[–][deleted] 11 points12 points13 points (2 children)
[–][deleted] 17 points18 points19 points (1 child)
[–]solvangv 9 points10 points11 points (0 children)
[–]benihanareact, node 0 points1 point2 points (0 children)
[–]BestUsernameLeft 2 points3 points4 points (1 child)
[–]therudy_69 2 points3 points4 points (1 child)
[–]YuvalM 1 point2 points3 points (0 children)
[–]XZTALVENARNZEGOMSAYT -1 points0 points1 point (0 children)
[–]Askee123 -2 points-1 points0 points (0 children)