== Why is this an issue?

Assertions are statements that check whether certain conditions are true. They are used to validate that the actual results of a code snippet match the expected outcomes. By using assertions, developers can ensure that their code behaves as intended and identify potential bugs or issues early in the development process.

In Chai.js, there is no inherent problem with giving the same argument twice in an assertion. It won't cause any errors or issues in the test execution itself. The test will still run and pass as long as the assertion is correct.

However, having the same argument twice in an assertion might indicate a design issue or a potential mistake in your test. In most cases, you don't need to compare a variable to itself in a test, as it doesn't provide any meaningful validation and is likely to be a bug due to the developer's carelessness.

This rule raises an issue when a Chai assertion is given twice the same argument.

[source,javascript,diff-id=1,diff-type=noncompliant]
----
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: Asserting the same argument
    });
});
----

Make sure that the arguments of your assertions are not the same.

[source,javascript,diff-id=1,diff-type=compliant]
----
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);
    });
});
----

== Resources
=== Documentation

* Chai.js Documentation - https://www.chaijs.com/api/[API Reference]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== 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


'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
