user10518298
user10518298

Reputation: 189

How to document javascript unit test files using jsdoc?

I have a react project and I am using jest to write unit and integration tests. I want to use jsdoc to document those files.

But dont know how ? didn't find anything in the jsdoc page. Can anyone help me with an example if its possible.

Upvotes: 2

Views: 3085

Answers (2)

Md. Noor-A-Alam Siddique
Md. Noor-A-Alam Siddique

Reputation: 1077

To generate unit test report like JSDoc for your unit test cases, use coverage flag on your npm test.

Lets say you wrote some test cases and want to generate report along with test case result and details, Here is an example with flag.

npm run test -- --coverage --watchAll=false --coverageDirectory=../outside_folder_path/_test_report_/

--coverage flag will create coverage folder inside of your project root and generate report like JSDoc create.

--coverageDirectory=../outside_folder_path/_test_report_/ flag will generate report like JSDoc create in your given folder_path.

Sample test report

Sample test report

Upvotes: 0

zsgomori
zsgomori

Reputation: 516

Documenting unit tests isn't an appropriate and clear way. Put simply, I'd rather create efficient test suites along with pretty clear explanations, in order to avoid any specific documentation in tests. Afterwards, the tests' suites will resemble to a complete documentation and they'll also tell about what the current method is doing.

Here is an example to demonstrate the stuff above with Jest:

desscribe('<ComponentName />', () => {
   describe('button click', () => {
      it('calls exampleFunction', () => {
         expect(exampleFunction).toHaveBeenCalled();
      });
   });
});

I'm not an expert in integration testing, but if you'd really like to stay with the point to document your tests, the page of jsdoc is quite straightforward to me.

Upvotes: 1

Related Questions