|
1 |
| -import { classNamesToTypeDefinitions } from "../../lib/typescript"; |
| 1 | +import { classNamesToTypeDefinitions, ExportType } from "../../lib/typescript"; |
2 | 2 |
|
3 | 3 | describe("classNamesToTypeDefinitions", () => {
|
4 |
| - it("converts an array of class name strings to type definitions", () => { |
5 |
| - const definition = classNamesToTypeDefinitions(["myClass", "yourClass"]); |
| 4 | + describe("named", () => { |
| 5 | + it("converts an array of class name strings to type definitions", () => { |
| 6 | + const definition = classNamesToTypeDefinitions( |
| 7 | + ["myClass", "yourClass"], |
| 8 | + "named" |
| 9 | + ); |
6 | 10 |
|
7 |
| - expect(definition).toEqual( |
8 |
| - "export const myClass: string;\nexport const yourClass: string;\n" |
9 |
| - ); |
| 11 | + expect(definition).toEqual( |
| 12 | + "export const myClass: string;\nexport const yourClass: string;\n" |
| 13 | + ); |
| 14 | + }); |
| 15 | + |
| 16 | + it("returns null if there are no class names", () => { |
| 17 | + const definition = classNamesToTypeDefinitions([], "named"); |
| 18 | + |
| 19 | + expect(definition).toBeNull; |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe("default", () => { |
| 24 | + it("converts an array of class name strings to type definitions", () => { |
| 25 | + const definition = classNamesToTypeDefinitions( |
| 26 | + ["myClass", "yourClass"], |
| 27 | + "default" |
| 28 | + ); |
| 29 | + |
| 30 | + expect(definition).toEqual( |
| 31 | + "interface Styles {\n 'myClass': string;\n 'yourClass': string;\n}\n\ndeclare const styles: Styles;\n\nexport default styles;\n" |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it("returns null if there are no class names", () => { |
| 36 | + const definition = classNamesToTypeDefinitions([], "default"); |
| 37 | + |
| 38 | + expect(definition).toBeNull; |
| 39 | + }); |
10 | 40 | });
|
11 | 41 |
|
12 |
| - it("returns null if there are no class names", () => { |
13 |
| - const definition = classNamesToTypeDefinitions([]); |
| 42 | + describe("invalid export type", () => { |
| 43 | + it("returns null", () => { |
| 44 | + const definition = classNamesToTypeDefinitions( |
| 45 | + ["myClass"], |
| 46 | + "invalid" as ExportType |
| 47 | + ); |
14 | 48 |
|
15 |
| - expect(definition).toBeNull; |
| 49 | + expect(definition).toBeNull; |
| 50 | + }); |
16 | 51 | });
|
17 | 52 | });
|
0 commit comments