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

conform() with Sets added too many items #45

Merged
merged 2 commits into from
Aug 27, 2017

Conversation

mattbishop
Copy link
Contributor

@mattbishop mattbishop commented Aug 19, 2017

js.spec's Set handling is broken WRT conform() output. The returned Set includes an extra 'length' field.
This PR fixes how conform assembles the return value. It upgrades the unit testing to chai 4 to gain improved Set assertions.

@mattbishop mattbishop changed the title BROKEN: Stricter tests to show broken Set handling conform() with Sets added too many items Aug 19, 2017
@mattbishop mattbishop force-pushed the sets-broken branch 2 times, most recently from d0b315a to 0471cdd Compare August 19, 2017 05:18
@@ -6,6 +6,12 @@ import { explainData } from "../../index";
import { invalid, count, minCount, maxCount } from "../../lib/symbols";

describe("collection", () => {
describe("factory", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Coveralls was complaining about reduced test coverage so I added a new test to increase coverage.

return invalid;
}
ret[key] = conformed;
const spreadValue = p.array(value) ? value : [...value];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for / of was adding in a length key, which was the source of this bug. Using spread operator converts the Set to an array with simpler map / filter functions.

"eslint": "^4.4.1",
"eslint-plugin-prettier": "^2.1.2",
"mocha": "^3.1.2",
"chai": "^4.1.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set testing was broken in old unit testing libs. I upgraded these together to the latest version to be safe.


expect(spec.conform(new Set([1, 2])), "set - count, happy").to.be
.a("Set")
.that.contains(1, 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deep.equal failed for Sets. It considered the two Sets equal, even though one has 3 elements and the other has 2.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Related -> chaijs/deep-eql#4

@arichiardi
Copy link
Collaborator

LGTM

@mattbishop
Copy link
Contributor Author

@prayerslayer any comments on this PR?

@arichiardi arichiardi merged commit c35538c into prayerslayer:master Aug 27, 2017
@arichiardi
Copy link
Collaborator

Will push a new version as well

@mattbishop mattbishop deleted the sets-broken branch August 27, 2017 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants