Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created December 19, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DawnImpulse/e89275206bcc5ddb4387fce8e326f341 to your computer and use it in GitHub Desktop.
Save DawnImpulse/e89275206bcc5ddb4387fce8e326f341 to your computer and use it in GitHub Desktop.
riteway + @hapi/joi
describe("uuid()", async (assert) => {
assert({
given: "nothing",
should: "generate a 32 chars alphanumeric string",
actual: validate(
generate.uuid(),
Joi.string()
.alphanum()
.length(32),
),
expected: true,
});
});
// this code is in typescript (you can avoid types in javascript)
import { AnySchema } from "@hapi/joi";
export default function validate<T>(value: T, schema: AnySchema): boolean {
const { error } = schema.validate(value);
return error == undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment