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

test: add test cases for parse date and random object #92

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rhuanbarreto
Copy link

@rhuanbarreto rhuanbarreto commented May 9, 2024

This PR is still failing tests. This is to show that the complex object case is failing.

@rhuanbarreto rhuanbarreto marked this pull request as ready for review May 10, 2024 00:31
@mrctrifork
Copy link

Those are edge-cases that cannot be solved.

The problem is that you'd require the TypeBox schema on Eden's side of things to be able to decode a JSON into it's declared schema because in JSON there's no way to tell apart a Date from a plain string.

Therefore Eden does a best-effort and if a string looks like an ISO8601 Date it goes ahead and parses it into a Date because that's what 99% of developers would do.

If you need the string on the client-side you can still call toISOString()

@rhuanbarreto
Copy link
Author

I agree that the "smartness" of checking if a value is a date by regexing it is fair enough.

But at least the "get random object" test should pass because 99% of the developers as you say would expect a date inside an object coming as a Date object from a JSON response. Same for the WebSocket failure.

@NanoSpicer
Copy link
Contributor

NanoSpicer commented May 10, 2024

Havent fully gone through the code as I am on the go, but I'll check it later. Should be easy enough to fix

@mrctrifork
Copy link

I just cloned your fork and ran the tests.

I do believe the test case you wrote is still one of these edge-cases that cannot be solved; as the toEqual expects property g to be a string but eden parses that into a Date since the value of g looks like a Date. Therefore a string representing a Date is not equal to an actual Date object.

As I mentioned in my previous comment; you cannot really solve this ambiguity problem (whether to parse a string that looks like a date or not) without the actual specification TypeBox schema definition.

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.

3 participants