-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
refactor: email test cases #276
Conversation
✅ Deploy Preview for valibot canceled.
|
Thanks for continuing to Valibot creating this PR! Do you know if there is a way to group related tests? For example, tests to check valid values, tests to check invalid values, and so on. |
@fabian-hiller We could wrap the tests in another describe for grouping. I was also thinking to create a helper function which takes as an argument validate._parse(value) and returns true or false.
or
|
I think I like the grouping but I am not sure about the utility functions. I like that the tests show the raw code, but on the other hand I also see the advantage of making the code more readable and simple. If we were to create a helper function for this, I would choose the following API: expect(isValidParse(validate, value)).toBeTruthy();
expect(isValidParse(validate, value)).toBeFalsy(); Do you have an idea for alternative names for the utility function? Maybe |
@fabian-hiller i also like tests showing raw code, but readable tests are also important so my suggestion is following:
|
Looks good to me. Feel free to implement this for some tests so we can compare. A disadvantage of this approach is that not everything can be covered with |
@fabian-hiller what do you think about this PR and parseValidation? If you agree, we could merge it and i refactor current mac and bic tests? |
I will give you feedback today or in the next few days. |
@fabian-hiller any update on this? |
It's on my list. I have not forgotten. By the end of next week I will be working full time on Valibot for the next few weeks. I expect big progress on the source code and documentation. |
@fabian-hiller i was thinking, maybe we could have some status in validation, which is setled, based on validation true, false, besides issues array of validation messages. |
What is the advantage of such an status key in your eyes? So far I have consciously decided against it for the internal code because it was not necessary. For external use of a schema, for example with |
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 the more fine-grained tests with a separate message for each case. I also like the 3-layer system (the grouping) with the nested describe
. I am not sure about the parseValidation
function, because I think it is better not to add an abstraction here. Currently I tend not to use it. Also, instead of just testing .output
, I think that I would prefer if we test the entire object returned by email
. Feel free to give me feedback on this.
Thank you again for your contribution. I will try to review it the next days and give you feedback. |
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 PR looks good now. There is only one thing I would change. I think instead of just testing the output, we should test the whole object returned by ._parse
. This makes the tests safer. What do you think?
// Old
test('should pass standard email', () => {
const value = '[email protected]';
expect(validate._parse(value).output).toBe(value);
});
// New
test('should pass standard email', () => {
const value = '[email protected]';
expect(validate._parse(value)).toEqual({ output: value });
});
Once this PR is merged, I recommend creating another PR for the tests of the |
@fabian-hiller i agree to compare with output object. |
Thanks for updating this PR! I will review it again next week and probably merge it. |
@fabian-hiller please check PR #366 for string schema refactored tests. |
Please have a look an review my changes. Note: I have removed the "should return custom error message" test because after the refactor of #397 we will pass the entire context to |
@fabian-hiller it looks ok. |
Thank you very much! Once i18n, the docs, and one or two other features are shipped, I will focus much more on unit testing. |
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
describe('should return action object', () => { | ||
test('should contain the default message', () => { | ||
expect(email()).toMatchObject({ |
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.
Is .toMatchObject()
less strict than .toEqual()
? Why do you choose it here?
b997a0f
to
6d0cde4
Compare
Thank you again for this PR Aris! I added your tests to the rewrite of Valibot in this commit. |
@fabian-hiller Here is my proposal for email test cases. I fixed regex so it supports
max 64 chars in local part of email value and 255 chars in domain part.