![github-actions[bot]](/assets/img/avatar_default.png)
* Add javascript to rule S2187 * Update metadata and description * Update rules/S2187/javascript/rule.adoc Co-authored-by: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com> * Update rules/S2187/javascript/rule.adoc Co-authored-by: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com> --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com> Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com>
45 lines
1.4 KiB
Plaintext
45 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Test files in JavaScript and TypeScript are meant to contain test cases. These test cases are used to verify the functionality of your code and ensure that it behaves as expected. If a test file doesn't contain any test cases, it's not serving its purpose.
|
|
|
|
A test file without test cases might indicate:
|
|
|
|
* An incomplete test suite: Perhaps the developer started writing tests but didn't finish.
|
|
* A mistake: The developer might have accidentally deleted the test cases or moved them to another file.
|
|
|
|
This rule flags any file that has ``++.test++`` or ``++.spec++`` as part of its suffix but does not contain any test cases defined using the different forms of the ``++it++`` and ``++test++`` functions from Jasmine, Jest, Mocha, or Node.js testing API.
|
|
|
|
== How to fix it
|
|
|
|
Add test cases to the file or delete it if it isn't needed anymore.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
// eval.test.js
|
|
|
|
/* no test cases */
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
// eval.test.js
|
|
|
|
it('1 + 2 should give 3', () => {
|
|
expect(1 + 2).toBe(3);
|
|
});
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Jasmine docs - https://jasmine.github.io/api/edge/global[API]
|
|
* Jest docs - https://jestjs.io/docs/api[API]
|
|
* Mocha docs - https://mochajs.org/#getting-started[API]
|
|
* Node.js docs - https://nodejs.org/api/test.html[API]
|