Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn against a non-object expected value given to propEqual #90

Closed
Krinkle opened this issue Jun 20, 2020 · 3 comments · Fixed by #148
Closed

Warn against a non-object expected value given to propEqual #90

Krinkle opened this issue Jun 20, 2020 · 3 comments · Fixed by #148

Comments

@Krinkle
Copy link
Contributor

Krinkle commented Jun 20, 2020

propEqual (docs) is for the strict-equality comparing of own properties of two objects. When the actual value is a non-object, such as a string, it can act in somewhat unexpected ways.

For example:

const actual = 'fuh';
assert.propEqual(actual, 'foo');
severity: failed
actual: {
  "0": "f",
  "1": "u",
  "2": "h"
}
expected: {
  "0": "f",
  "1": "o",
  "2": "o"
}

This is because the values compared are the boxed-object equivalent of the strings. Similar to what Object('foo'), or new String('foo'), or 'foo'.split('') would produce.


Ref qunitjs/qunit#411 (comment).

@platinumazure
Copy link
Owner

Yes, let's create a new rule for this. Open to name suggestions.

I also think this probably should be added to recommended in a major release. I think it's probably too late to do this for the current upcoming major release but we'll see.

@Krinkle Krinkle changed the title Warn against an non-object expected value given to propEqual Warn against a non-object expected value given to propEqual Jun 21, 2020
@platinumazure
Copy link
Owner

Working on this.

@platinumazure
Copy link
Owner

I've created #148 to implement this.

platinumazure added a commit that referenced this issue Mar 9, 2021
* New: use-object-in-propequal rule (fixes #90)

* Chore: Remove bigint tests until we drop support for ESLint 5

* Update: Allow array expressions

* Chore: Rename rule to require-object-in-propequal

* Chore: Fix rule id in test file

* Chore: Fix README to account for rule name update

* Update: Support optional expressions

* Chore: Improve logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants