Should I check the private functions of the Javascript plugin?

I am trying to write test javascript. Testing every feature, I know, is crucial. But I came to a stumbling block, because the plugin I am writing must have some private functions. I can’t understand how they work. What do I need to do if I want my code to be well tested without changing its structure too much? (I'm fine with exposing some APIs, albeit within.)

I use sinon, QUnit and Pavlov.

+4
source share
1 answer

If you are doing test development (as suggested by tags), each line of production code is first justified by an unsuccessful test case.

In other words, the existence of every line of your production code is implicitly checked, because without it some test should have failed. At the same time, you can safely assume that the private function / lambda / close has already been checked from the definition of TDD.

If you have a private function, and you are interested in how to test it, this means that you did not do TDD in the first place - and now you have a problem.

To summarize - never write production code before a test. If you follow this rule, each line of code is checked regardless of depth.

+3
source

All Articles