Skip to content

Way to validate group? #1158

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

Open
heohex opened this issue Feb 27, 2025 · 2 comments
Open

Way to validate group? #1158

heohex opened this issue Feb 27, 2025 · 2 comments

Comments

@heohex
Copy link

heohex commented Feb 27, 2025

Hi! Is it possible to validate all group?

For example

import { create, test, each, enforce, group } from 'vest';

/*
data.fields = [
  {
    name: 'GameBoy Color',
    price: 200,
    id: "gb-color"
  },
  {
    name: 'GameBoy Advance',
    price: 300,
    id: "gb-advance"
  },
  {
    name: 'Nintendo 64',
    price: 400,
    id: "n64"
  },
]
*/

const suite = create((data = {}) => {
  group("myAwesomeGroup", () => {
    each(data.fields, field => {
      test(
        field.name,
          "item price must be greater than 0",
            () => { enforce(field.price).isNumeric().greaterThan(0)},
            field.id,
       )
    })
  })
})

and after it call something like suit.validate("myAwesomeGroup")

@ealush
Copy link
Owner

ealush commented Feb 27, 2025 via email

@heohex
Copy link
Author

heohex commented Feb 28, 2025

@ealush Thanks a lot!

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