33 lines
1.0 KiB
Plaintext
33 lines
1.0 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]
|
|
----
|
|
describe("MyClass", function () {
|
|
it.only("should run correctly", function () {
|
|
/*...*/
|
|
});
|
|
});
|
|
----
|
|
|
|
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]
|
|
----
|
|
describe("MyClass", function () {
|
|
it("should run correctly", function () {
|
|
/*...*/
|
|
});
|
|
});
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
- https://mochajs.org/#exclusive-tests[exclusive tests in Mocha]
|
|
- https://jestjs.io/docs/next/api#testonlyname-fn-timeout[test.only() in Jest]
|
|
- https://jestjs.io/docs/next/api#describeonlyname-fn[describe.only() in Jest]
|