53 lines
1.3 KiB
Plaintext

Many assertion functions have specific parameters for the expected and actual values. Swap them, and your test will still have the same outcome (succeed/fail when it should) but the error messages will be confusing.
This rule raises an issue when the "expected" argument of an assertion function is a hard-coded value and the "actual" argument is not.
This rule currently supports Chai assertions.
== Noncompliant Code Example
----
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();
it("inverts arguments", function() {
assert.equal(42, aNumber); // Noncompliant
expect(42).to.equal(aNumber); // Noncompliant
should.fail(42, aNumber); // Noncompliant
});
----
== Compliant Solution
----
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();
it("inverts arguments", function() {
assert.equal(aNumber, 42);
expect(aNumber).to.equal(42);
should.fail(aNumber, 42);
});
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]