From fd8d602c15f4660872d17debbb1d00200b189dde Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Sun, 29 May 2022 15:02:07 +0200 Subject: [PATCH] Show example of function message (#1674) --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 73628d722..146eb41a2 100644 --- a/README.md +++ b/README.md @@ -1087,11 +1087,13 @@ let jimmySchema = string().test( ); // or make it async by returning a promise -let asyncJimmySchema = string().test( - 'is-jimmy', - '${path} is not Jimmy', - async (value, testContext) => (await fetch('/is-jimmy/' + value)).responseText === 'true', -}); +let asyncJimmySchema = string() + .label('First name') + .test( + 'is-jimmy', + ({ label }) => `${label} is not Jimmy`, // a message can also be a function + async (value, testContext) => (await fetch('/is-jimmy/' + value)).responseText === 'true', + }); await schema.isValid('jimmy'); // => true await schema.isValid('john'); // => false