Skip to content

Support for nested suites  #1141

Description

@codrin-iftimie

I'm researching libraries that can be used to replace my in-house form validator library. I'm using generators at the moment.
Most of the requirements this library checks them. Kudos for that.
But, one of the common requirements is the ability to nest validators to ensure good code reusability.
Let's take this as an example

const itemSuite = create(() => {
  test('field1', 'Field1 is invalid' () => {
    //
  })
})

const mainSuite = create((items) => {
  test('items', 'One or more item is invalid' () => {
    ensure(data.items).matchesArrayOfSuite(itemSuite)
  })

  test('innerItem', 'This inner item is not valid', () => {
    ensure(data.innerItem).matchesSuite(itemSuite)
  })
})

In some cases, I'd like to use the itemSuite to validate an item object on a "details" page where there are independent CRUD operations for each item.
In other cases, I have a wizard where we allow the user to add these items as part of a bigger payload (see mainSuite).
I know that matchesArrayOfSuite nor matchesSuite is not part of the current enforce API. Is there any plan to support something similar to this that would allow nesting suites?
Expectations would be to see a general error on items and innerItem if the object is not valid, but also have mainSuite to inherit the details from itemSuite to show them to their respective fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions