-
Notifications
You must be signed in to change notification settings - Fork 579
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
Ensure that Realm enums are accessible #5484
Conversation
describe("ConnectionState", function () { | ||
it("is accessible", function () { | ||
expect(typeof ConnectionState === "object"); | ||
expect(typeof ConnectionState.Disconnected === "string"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be redundant to check all enum values, feel free to add thoughts about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote for keeping them (i.e. testing all values). Even though the issue mentioned asserting that the value is a string, we'd get more accurate tests if we compare it to the actual string value (e.g. "disconnected"
).
On a smaller note, perhaps we want to structure them more toward "natural language"? E.g.:
// This will pass for e.g. arrays as well.
expect(typeof ConnectionState).to.equal("object");
// This will not pass for arrays.
expect(ConnectionState).to.be.an("object");
expect(ConnectionState.Disconnected).to.equal("disconnected");
expect(ConnectionState.Connecting).to.equal("connecting");
// Fixed typo from `Connecting` to `Connected`
expect(ConnectionState.Connected).to.equal("connected");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah went through this a bit too fast 🤦 using mocha as extensively as possible is what we've already done in test-migration-master
so should aim for that! Thanks for pointing it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Np 👍 (perhaps to.deep.equal()
could test all those cases at once as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be redundant to check all enum values.
I'm probably feeling this a bit. If these tests fail it'll either be because we (hopefully consciously) changed the enums or the TS compiler is broken (in which case this will be the least of our worries). These tests are in risk of becoming outdated if we add new values to the enum.
The main reason we had these issues on master
was because we declared types separately from implementation (in JS), so I probably don't feel the need for this to be a part of our test suite. But then again - they are written now, so they don't hurt too much to keep 😅
(and sorry for being late to the party here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :D Got some suggestions 👍
describe("ConnectionState", function () { | ||
it("is accessible", function () { | ||
expect(typeof ConnectionState === "object"); | ||
expect(typeof ConnectionState.Disconnected === "string"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote for keeping them (i.e. testing all values). Even though the issue mentioned asserting that the value is a string, we'd get more accurate tests if we compare it to the actual string value (e.g. "disconnected"
).
On a smaller note, perhaps we want to structure them more toward "natural language"? E.g.:
// This will pass for e.g. arrays as well.
expect(typeof ConnectionState).to.equal("object");
// This will not pass for arrays.
expect(ConnectionState).to.be.an("object");
expect(ConnectionState.Disconnected).to.equal("disconnected");
expect(ConnectionState.Connecting).to.equal("connecting");
// Fixed typo from `Connecting` to `Connected`
expect(ConnectionState.Connected).to.equal("connected");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, just a minor suggestion
expect(typeof NumericLogLevel.Trace === "number"); | ||
expect(typeof NumericLogLevel.Warn === "number"); | ||
expect(NumericLogLevel).to.be.an("object"); | ||
expect(NumericLogLevel.All).equals(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively you could possibly (but I am not sure if this will work?) do a deep equal with an object i.e.
expect(NumericLogLevel).deep.equals({
All: 0,
Trace: 1
...
});
This might be better as well in case in the future we add a new value to the enum, as it would cause the test to fail, which it wouldn't with the current approach. Same for other enums. Again, not sure if this will work how I think it'll work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized @elle-j had the same idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a shot, was a bit concerned that the syntax would make it less readable but the point with adding new values is very valid!
I added the |
expect(NumericLogLevel).to.be.an("object"); | ||
expect(NumericLogLevel).to.deep.equals({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first line shouldn't be needed when you're doing deep equals to an object. Btw, does it still work with having the s
at the end of equal
? (I'd vote for where you're using to.deep.equal()
) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, most of these "to" "be" "equal/equals" are just meaningless syntactic sugar that does not change its behavior. So it could be expect(NumericLogLevel).deep.equals
or expect(NumericLogLevel).to.deep.equal
. I like both, I have generally been using the former for less use of this chaining but the latter does read nicer.
}); | ||
describe("NumericLogLevel", function () { | ||
it("is accessible", function () { | ||
expect(NumericLogLevel).to.deep.equal({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and we do use .deep.equals
161 trimes and .to.deep.equal
9 times... with that in mind I am leaning towards being consistent... sorry for leading you wrong way but I don't feel strongly about this if others don't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like consistency so I appreciate that you lifted this :D
* bindgen: Implement getAllSyncSessions (#5492) Ensure that Realm enums are accessible (#5484) Apply suggestions from code review [skip ci] Small corrections [skip ci] Added changelog and final corrections Stub add test to validate that foreach throws on a dictionary (#5467) Using `RealmInsertionModel` on `Results#update` Updated "react-native" dev dep to 0.71.0 Bumped lower bound on our RN peer dependency [bindgen] SDK packaging (#5466) Adding "prebuild" and configuring it (#5447) add synthetic private brand fields to TS wrappers for C++ classes, and fix found bug import bindings directly rather than through internal Stub work
Small tests to make sure that the issue in #3365 is resolved