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

Two different Options .should.not.eql each other #1296

Open
matthew-white opened this issue Nov 13, 2024 · 1 comment · May be fixed by #1297
Open

Two different Options .should.not.eql each other #1296

matthew-white opened this issue Nov 13, 2024 · 1 comment · May be fixed by #1297
Assignees
Labels
testing Integration tests, unit tests

Comments

@matthew-white
Copy link
Member

#1287 removes direct access to the value property of Option objects. That caused Ramda to consider all Options to be equal, so the PR also added an equals() method to Option. However, I'm realizing that there's a similar issue with Should.js. Now that it doesn't have access to value, eql() (AKA deepEqual()) no longer throws for two different Options. For example:

// This passes.
Option.of(1).should.eql(Option.of(2));

We have tests with assertions like that. I noticed this issue while looking at #1291, where you can see this test:

it('should pass through any field key content', (done) => {
const request = createRequest({ url: '/key/12|45/users/23' });
fieldKeyParser(request, null, () => {
request.fieldKey.should.eql(Option.of('12|45'));
request.url.should.equal('/users/23');
done();
});
});

If I change Option.of('12|45') to something else in the test, the test continues to pass.

It looks like Should.js still distinguishes between empty and non-empty Options, since they have different prototypes.

Instead of using a private property like #value in Option, how about using something like _value or Symbol('value')? I think those would signal effectively that the property isn't meant to be used outside the class.

@matthew-white matthew-white added the testing Integration tests, unit tests label Nov 13, 2024
@github-project-automation github-project-automation bot moved this to 🕒 backlog in ODK Central Nov 13, 2024
@matthew-white matthew-white changed the title Two different options .should.not.eql each other Two different Options .should.not.eql each other Nov 13, 2024
alxndrsn pushed a commit to alxndrsn/odk-central-backend that referenced this issue Nov 14, 2024
Making Option.value a private field broke should(Option).eql() behaviour.

See: getodk#1287 / 5ef4c72

Closes getodk#1296
@alxndrsn alxndrsn linked a pull request Nov 14, 2024 that will close this issue
@alxndrsn
Copy link
Contributor

I've tried to address this in #1297

@matthew-white matthew-white moved this from 🕒 backlog to ✏️ in progress in ODK Central Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Integration tests, unit tests
Projects
Status: ✏️ in progress
Development

Successfully merging a pull request may close this issue.

2 participants