Skip to content

Commit b2ddfe7

Browse files
Add basic tests for tsIntersectionOf
1 parent 334f806 commit b2ddfe7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/utils.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { tsUnionOf } from "../src/utils";
2+
import { tsIntersectionOf } from "../src/utils";
23

34
describe("utils", () => {
45
describe("tsUnionOf", () => {
@@ -18,4 +19,26 @@ describe("utils", () => {
1819
return expect(tsUnionOf(...[0, true, "string", '"hello"'])).toBe('0 | true | string | "hello"');
1920
});
2021
});
22+
23+
describe("tsIntersectionOf", () => {
24+
const tests: [string, string[], string][] = [
25+
["identity for single type", ["string"], "string"],
26+
["basic intersection", ["string", "number"], "string & number"],
27+
["filter out unknown", ["string", "number", "unknown"], "string & number"],
28+
["identity for unknown type", ["unknown"], "unknown"],
29+
["unknown for no types passed", [], "unknown"],
30+
["parentheses around types with union", ["4", `string | number`], "4 & (string | number)"],
31+
[
32+
"parentheses around types with intersection",
33+
["{ red: string }", "{ blue: string } & { green: string }"],
34+
"{ red: string } & ({ blue: string } & { green: string })",
35+
],
36+
];
37+
38+
tests.forEach(([name, input, output]) => {
39+
test(name, () => {
40+
expect(tsIntersectionOf(...input)).toBe(output);
41+
});
42+
});
43+
});
2144
});

0 commit comments

Comments
 (0)