2023-05-03 11:06:20 +02:00
== Why is this an issue?
2020-12-21 15:38:52 +01:00
Many assertions compare two objects or properties of these objects. Passing twice the same argument is likely to be a bug due to developer's carelessness.
2021-02-02 15:02:10 +01:00
2020-12-21 15:38:52 +01:00
This rule raises an issue when a Chai assertion is given twice the same argument.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-12-21 15:38:52 +01:00
----
const assert = require('chai').assert;
describe("test the same object", function() {
it("uses chai 'assert'", function() {
const expected = '1'
const actual = (1).toString()
assert.equal(actual, actual); // Noncompliant
});
});
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-12-21 15:38:52 +01:00
----
const assert = require('chai').assert;
describe("test the same object", function() {
it("uses chai 'assert'", function() {
const expected = '1'
const actual = (1).toString()
assert.equal(actual, expected);
});
});
----
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Replace this argument or its duplicate at position [X].
=== Highlighting
If the same argument is passed twice to the same function
* Primary: the first expression occurence
message: 'Refactor this assertion to not pass the same argument twice.'
* Secondary: the second expression occurence
message: 'Argument [POSITION] has the same value.'
If the assertion is of the form ``++expect(obj).a(obj, other1)++``
* Primary: the duplicate argument.
message: 'Refactor this assertion to not pass the same value as in "expect()".'
* Secondary: the argument of "expect".
If the assertion is of the form ``++obj.should.be.closeTo(obj, other1, other2)++``
* Primary: the duplicate argument.
message: Refactor this assertion to not use the same value as the one asserted by "should".
* Secondary: the variable on which "should" is called.
no message
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2023-06-22 10:38:01 +02:00
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]