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

isDate alway fails #1120

Closed
NormandoHall opened this issue Dec 27, 2023 · 7 comments
Closed

isDate alway fails #1120

NormandoHall opened this issue Dec 27, 2023 · 7 comments

Comments

@NormandoHall
Copy link

NormandoHall commented Dec 27, 2023

Fail:

enforce('2020-04-15').isDate();
enforce('15/04/2020').isDate({ format: 'DD/MM/YYYY' });

No fails:

enforce(new Date()).isDate();

Node: v18.18
Vest: 5.2.3

The same happens importing external rules from validator or using built in plugins.

EDIT: Seems an issue with validator?

validatorjs/validator.js#2256

EDIT2:

Yes, there is an issue with validator. A quick and dirty workaround for me is parsing with dayjs and convert to Date object. No fails with the format, but not validates de date.

import { create, test, enforce } from 'vest';
import 'vest/enforce/date';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat.js';

dayjs.extend(customParseFormat);

const suite = create((data = {}, currentField) => {

  // ...

  test('birthDate', 'Fecha Nacimiento inválida', () => {
    enforce(dayjs(data.birthDate, 'DD/MM/YYYY').toDate()).isDate();
  });

});

export default suite;
@ealush
Copy link
Owner

ealush commented Dec 27, 2023

Hi @NormandoHall, thanks for reaching out!

I just checked both examples that you supplied, and they both seem to be passing:
image

On the right hand side you're seeing the proxy Object being returned from enforce, instead of an error being thrown - which means that isDate does indeed pass.

I am wondering how it looks inside your suite, there may be something else at play. Do you have a quick repro sandbox that I can take a look at?

@NormandoHall
Copy link
Author

NormandoHall commented Dec 27, 2023

Hi @ealush, Thanks for your quick reply.

I have forked your svelte example sandbox, and added the form field "birthDate" and added the test in the suite, and still fails.

https://codesandbox.io/p/sandbox/svelte-vest-5-isdate-fail-vtdzjw

@ealush
Copy link
Owner

ealush commented Dec 27, 2023

@NormandoHall
No changes to your code whatsoever, it seems to work correctly.

Can you try just inputting this:
01/08/1990
I am wondering if it's related to trimming, special ascii characters, or something else I can't think of - because your code works.

See screencap
birthdate

@NormandoHall
Copy link
Author

It is very strange. I tested 01/08/1990 and fails. Tested with Chrome, Edge, and Firefox

vest.mp4

@NormandoHall
Copy link
Author

NormandoHall commented Dec 28, 2023

Well, with vest@5.1.0 runs ok (maybe because uses validator@13.9.0)

@ealush
Copy link
Owner

ealush commented Dec 28, 2023

OK. I think you are right. I had the 13.9.0 locally installed and that's why I did not experience this. I downgraded and now I see this.

Releasing now a patch version of Vest with the lower validator version. Will be out in a few moments.

@NormandoHall
Copy link
Author

@ealush, now runs like a charm.

Thank you!

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

No branches or pull requests

2 participants