32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When using testing frameworks like Mocha and Jest, appending `.only()` to the test function allows running a single test case for a file. Using `.only()` means no other test from this file is executed. This is useful when debugging a specific use case.
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
describe("MyClass", function () {
|
|
it.only("should run correctly", function () { // Noncompliant
|
|
/*...*/
|
|
});
|
|
});
|
|
----
|
|
|
|
However, it should not be used in production or development, as it is likely a leftover from debugging and serves no purpose in those contexts. It is strongly recommended not to include `.only()` usages in version control.
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
describe("MyClass", function () {
|
|
it("should run correctly", function () {
|
|
/*...*/
|
|
});
|
|
});
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
- https://mochajs.org/#exclusive-tests[Mocha - Exclusive tests]
|
|
- https://jestjs.io/docs/next/api#testonlyname-fn-timeout[Jest - ``++test.only()++``]
|
|
- https://jestjs.io/docs/next/api#describeonlyname-fn[Jest - ``++describe.only()++``]
|