Skip to content

Conversation

@kentaromiura
Copy link
Contributor

Allows jest to check for equalities of Sets/Maps and Array-like by adding a custom equality tester for iterators.
Jasmine run custom equality before the normal equality checker, so I also add a test to ensure it didn't break normal Arrays equality (as they implement Symbol.iterator).

@kentaromiura kentaromiura force-pushed the adding-iterators-support branch from e95adf5 to 6be523c Compare April 21, 2016 04:18
*/
'use strict';

describe('compare iterables correctly', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call it iterators? :)

@cpojer
Copy link
Member

cpojer commented Apr 21, 2016

Looks good overall but I added some code-style recommendations.

let nextRight = rightIterator.next();

result = true;
while (result && !nextLeft.done) {
Copy link
Member

@cpojer cpojer Apr 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, instead of using a while loop, can't you just use a for of loop? That way you'll avoid doing the manual iterator advancement for at least one of the iterators.

for (const value of a) {
  if (!matches) {
    return false;
  }
  bIterator.next();
}

@kentaromiura kentaromiura force-pushed the adding-iterators-support branch from 148c682 to 6dc8831 Compare April 21, 2016 07:40
…me constructor, fixes tests, refactor code following comments
@kentaromiura kentaromiura force-pushed the adding-iterators-support branch from 6dc8831 to 79093d7 Compare April 21, 2016 08:49
!jasmine.matchersUtil.equals(
aValue,
nextB.value,
jestCustomEqualityTesters
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed for the recursive check

@cpojer
Copy link
Member

cpojer commented Apr 21, 2016

Looks great! Just a few minor comments – I recommend using the simplest possible solution to most things. You are unlikely to need some abstractions ever, so they just stay in the code until the end of time. It's better to pick the simple solution and extend it when needed :)

@kentaromiura
Copy link
Contributor Author

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in 292e9d0 Apr 27, 2016
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants