jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 294 forks source link

[BUG] #1183

Closed micahg closed 2 months ago

micahg commented 2 months ago

Describe the bug I can't seem to figure out how to make body object's optional but their properties mandatory.

To Reproduce

checkSchema({
    a: {
      in: ["body"],
      optional: true,
      custom: {
        options: (value) => validateRect(value),
        errorMessage: "Invalid a",
      },
    },
    "a.x": {
      in: ["body"],
      optional: false,
      isInt: {
        options: { min: 0 },
        errorMessage: "a x must be a non-negative integer",
      },
    },
  });

Expected behavior The behavior I want is for a body no a to pass validation BUT a body with an empty a to fail, eg:

pass:

{}

fail:

{
  a: {}
}

pass:

{
  a: {
    x: 1
  }
}

Environment (please complete the following information):

Prerequisite

Additional context

Thanks for helping - I know I can create a custom validator for the object - i was just wondering if there was a way to achieve this behaviour without.


The fastest (and the most fun) way to resolve the issue is to submit a pull request yourself. If you are interested, please check out the contribution guide, we look forward to seeing your PR...