Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed May 21, 2023
1 parent 133c9c6 commit 996083e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
13 changes: 1 addition & 12 deletions deno/lib/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ test("email validations", () => {
`user@my-example.com`,
`a@b.cd`,
`work+user@mail.com`,

`tom@test.te-st.com`,
`something@subdomain.domain-with-hyphens.tld`,
`francois@@etu.inp-n7.fr`,
Expand Down Expand Up @@ -147,24 +146,14 @@ test("email validations", () => {
`test@.com`,
];
const emailSchema = z.string().email();
for (const email of validEmails) {
emailSchema.parse(email);
}
for (const email of invalidEmails) {
try {
emailSchema.parse(email);
console.log(`PASS`, email);
} catch (_) {}
}

expect(
validEmails.every((email) => {
console.log("good", email);
return emailSchema.safeParse(email).success;
})
).toBe(true);
expect(
invalidEmails.every((email) => {
console.log("bad", email);
return emailSchema.safeParse(email).success === false;
})
).toBe(true);
Expand Down
20 changes: 15 additions & 5 deletions playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const validEmails = [
`user@my-example.com`,
`a@b.cd`,
`work+user@mail.com`,

`tom@test.te-st.com`,
`something@subdomain.domain-with-hyphens.tld`,
`francois@etu.inp-n7.fr`,
Expand All @@ -36,6 +35,9 @@ const invalidEmails = [
// `mailhost!username@example.org`,
// `test/test@test.com`,

// double @
`francois@@etu.inp-n7.fr`,

// do not support quotes
`"email"@domain.com`,
`"e asdf sadf ?<>ail"@domain.com`,
Expand Down Expand Up @@ -107,11 +109,19 @@ const invalidEmails = [
`gbacher0@[IPv6:bc37:4d3f:5048:2e26:37cc:248e:df8e:2f7f:af]`,
`invalid@[IPv6:5348:4ed3:5d38:67fb:e9b:acd2:c13:192.168.256.1]`,
];

const emailSchema = z.string().email();
for (const email of validEmails) {
console.log("good", email);
emailSchema.parse(email);
}
console.log(
validEmails.every((email) => {
const val = emailSchema.safeParse(email).success;
if (!val) console.log(`fail`, email);
return val;
})
);
// for (const email of validEmails) {
// console.log("good", email);
// emailSchema.parse(email);
// }
for (const email of invalidEmails) {
try {
emailSchema.parse(email);
Expand Down
13 changes: 1 addition & 12 deletions src/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ test("email validations", () => {
`user@my-example.com`,
`a@b.cd`,
`work+user@mail.com`,

`tom@test.te-st.com`,
`something@subdomain.domain-with-hyphens.tld`,
`francois@@etu.inp-n7.fr`,
Expand Down Expand Up @@ -146,24 +145,14 @@ test("email validations", () => {
`test@.com`,
];
const emailSchema = z.string().email();
for (const email of validEmails) {
emailSchema.parse(email);
}
for (const email of invalidEmails) {
try {
emailSchema.parse(email);
console.log(`PASS`, email);
} catch (_) {}
}

expect(
validEmails.every((email) => {
console.log("good", email);
return emailSchema.safeParse(email).success;
})
).toBe(true);
expect(
invalidEmails.every((email) => {
console.log("bad", email);
return emailSchema.safeParse(email).success === false;
})
).toBe(true);
Expand Down

0 comments on commit 996083e

Please sign in to comment.