-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.test.ts
31 lines (24 loc) · 1.01 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import validate from "./index";
test("Should be valid GTIN-8", () => {
const VALIDS: string[] = ["12345670", "96385074", "75395124"];
VALIDS.forEach((gtin: string) => expect(validate(gtin)).toBe(true));
});
test("Should be valid GTIN-12", () => {
const VALIDS: string[] = ["012345678905", "036000291452", "123456789012"];
VALIDS.forEach((gtin: string) => expect(validate(gtin)).toBe(true));
});
test("Should be invalid GTIN-8", () => {
const INVALIDS: string[] = ["1234567", "abcdefgh", "87654321"];
INVALIDS.forEach((gtin: string) => expect(validate(gtin)).toBe(false));
});
test("Should be invalid GTIN-12", () => {
const INVALIDS: string[] = ["01234567890", "03600029145", "999999999999"];
INVALIDS.forEach((gtin: string) => expect(validate(gtin)).toBe(false));
});
test("Should handle empty strings", () => {
expect(validate("")).toBe(false);
});
test("Should handle null or undefined values", () => {
expect(validate(null as any)).toBe(false);
expect(validate(undefined as any)).toBe(false);
});