Skip to content

fix multi validate with object strict remove #272

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

Merged

Conversation

0x0a0d
Copy link
Contributor

@0x0a0d 0x0a0d commented Sep 11, 2021

// similar to #210 but better understanding fastest-validator
Explain: when using multi validate with object strict remove option, if validation fails, it should not apply strict rule to object value

it("should pass object strict remove", () => {
  const v = new Validator({
    useNewCustomCheckerFunction: true,
  });
  
  v.alias("targetA", {
  type: "object", strict: "remove", props: {
    a: "number"
  }
  });
  
  v.alias("targetB", {
  type: "object", strict: "remove", props: {
    b: "number"
  }
  });
  
  const check = v.compile({
    $$root: true,
    type: "multi",
    rules: ["targetA", "targetB"]
  });
  const oo = {b: 2, c: 3};
  expect(check({a: 1})).toBe(true);
  expect(check(oo)).toBe(true);
  expect(oo).toEqual({b: 2});
});

@icebob icebob self-requested a review September 12, 2021 09:25
@icebob icebob requested a review from erfanium September 12, 2021 09:28
@icebob icebob merged commit a3421ed into icebob:master Sep 12, 2021
@0x0a0d 0x0a0d deleted the fix_multi_validator_with_object_strict_remove branch March 15, 2022 22:57
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

Successfully merging this pull request may close these issues.

3 participants