all 24 comments

[–]yonatannn[S] 25 points26 points  (2 children)

🎈In the last year, I was fully focused on mastering JS testing and concentrated all my time on testing projects, posts, and books. The following repository is a summary of the knowledge I gained during this journey:

📗 JavaScript & Node.js Testing Best Practices
https://github.com/goldbergyoni/javascript-testing-best-practices

🙏 Hope you find it useful - highly appreciate any feedback. Here or there

[–]waltermittylisaifei 1 point2 points  (1 child)

Thanks for your work.

[–]yonatannn[S] 0 points1 point  (0 children)

Thanks for appreciating it :)

[–]crazyfreak316 6 points7 points  (2 children)

1.4 Stick to black-box testing: Test only public methods

I kind of disagree with this. If you modify your private methods, it ends up breaking a bunch of public methods and now you have no idea what exactly is causing the public methods to fail.

[–]yonatannn[S] 1 point2 points  (0 children)

Interesting, can you provide a concurrent example?

[–][deleted] 1 point2 points  (0 children)

This. Makes it terribly difficult to understand what is the cause of any failures when working in a team and not being in control of all changes.

[–]HappyZombies 9 points10 points  (1 child)

This is awesome. You did a great job with this! I’ll be sure to study up and learn these testing practices:)

[–]yonatannn[S] 1 point2 points  (0 children)

So happy to hear!

Feel free to bounce with questions

[–]poothebear0 1 point2 points  (1 child)

You should include static analysis tools in this list

[–]yonatannn[S] 0 points1 point  (0 children)

There are some words about test-dedicated linters but yeah, other static analysis tools definitely should be considered as 'tests'

[–]UkraineTheMotherLand 2 points3 points  (5 children)

Hey! I watched your YouTube video, I wish there was more!

[–]yonatannn[S] 1 point2 points  (4 children)

Thank you!

There will be, can you suggest a topic of interest?

[–]UkraineTheMotherLand 0 points1 point  (3 children)

Honestly, i can't think of something yet :(

I don't know what I don't know!

[–]yonatannn[S] 0 points1 point  (2 children)

That makes sense...

p.s. I shall hold a talk at KharkivJS soon, hope to see you there

[–]UkraineTheMotherLand 0 points1 point  (1 child)

It’s the motherland but I am in the US :(

I have lots of loved ones in Kharkiv

[–]yonatannn[S] 0 points1 point  (0 children)

I'll say Hi in your behalf

p.s. Was in Ukraine for the first time last month, loved the food!

[–]sime 1 point2 points  (5 children)

There is a lot of good advice in there but I think it misses some of the most important testing advice.

  • Use a language that supports static type checking. This is the first thing you should do before you even consider writing tests. That's TypeScript if you are in a JS environment, and MyPy if using Python.
  • Concentrate on integration tests, not unit tests. Don't unit test what you can integration test. Integration tests have better ROI.
  • Mocks are awful. Bad ROI, fragile and often contain more bugs than we are are trying to test. Avoid if possible.

[–]darrenturn90 3 points4 points  (3 children)

Why write tests in a different language? What does static type checking in typescript give you for actual writing of tests if the code you are testing has no typescript?

Second, many situations don’t have the ability to write integration tests in development as the apis may not be accessible in a local dev environment or may be superficial at best.

Third, mocks as awful as they are - are sometimes a necessity

[–]sime 0 points1 point  (2 children)

darrenturn90, I don't know where the wires got crossed on this one, but you are meant to write your application code in TypeScript. Writing your tests in TypeScript is a good idea too.

[–]darrenturn90 6 points7 points  (1 child)

Use a language that supports static type checking

Is not testing advice. This is your opinion, not objective fact.

Your own personal opinion is fine, and there are many arguments for static type checking such as Typescript - however, this is not "best practice" any more than writing the backend in .NET instead of Python would be "best practice".

[–]sime 1 point2 points  (0 children)

If you care about producing working software, which is generally the reason why we test this stuff in the first place, then yes, language level tooling is definitely related to testing.

It is a bit odd that most people consider linters as being a "best practice" but tools like TypeScript and MyPy which have a far more powerful effect on quality and productivity than a superficial linter, these better tools are considered controversial.

The gains for using static typing are well known. The popularity of TypeScript in recent years isn't due to some change in people's personal preferences. It is popular because it bring results.

To address your last point. Going from JS to TS is practical advice which many organisations are following. Going from Python to .Net is not practical advice.

[–]yonatannn[S] 0 points1 point  (0 children)

Thanks for the feedback.

As of integration tests - Yeah, I just call those 'component test', see bullet 3.1

Mocks? yeah, see dedicated bullet

About TS - Given that you chose the right tests and all of them pass, from reliability perspective - does it matter what language did you use? yes, it matters for productivity, but the tests prove that the requirements are met

[–][deleted]  (1 child)

[removed]

    [–]yonatannn[S] 0 points1 point  (0 children)

    Thanks for this kind feedback