Skip to content

Conversation

@eps1lon
Copy link
Member

@eps1lon eps1lon commented Jan 11, 2021

Generally, expect(*) should always receive the "bare" object i.e. not include any property access. The reason being that in case of a mismatch you want to see actionable debug information from the matcher. Otherwise you almost always end up logging the actual value anyway once it fails. The exception to this rule is if you don't have useful matchers to use.

expect(sinonSpy.calledWith(value)).to.equal(true) is problematic for two reasons:

  • you don't see the actual value once it fails
  • you don't know which call it is or how often the spy was called at all

Specifically, DateTimePicker.test allows to select full date end-to-end was failing after internal refactoring (#24367). It didn't provide actionable information that revealed that the behavior was still correct, but the testing approach problematic. I used this opportunity to refactor the other usages of .calledWith.

I don't see how we can safely flag these uses statically no-restricted-properties has no information about the context so it might flag appropriate uses. I think the "no access on the left side of the assertion" is a better heuristic.

@eps1lon eps1lon added the test label Jan 11, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented Jan 11, 2021

No bundle size changes

Generated by 🚫 dangerJS against a185566

@eps1lon eps1lon merged commit 1fbc24f into mui:next Jan 12, 2021
@eps1lon eps1lon deleted the test/drop-calledWith branch January 12, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants