| 1 |
import { createTypeAnnotationBasedOnTypeof } from "../../../lib/index.js"; |
| 2 |
|
| 3 |
describe("builders", function () { |
| 4 |
describe("flow", function () { |
| 5 |
describe("createTypeAnnotationBasedOnTypeof", function () { |
| 6 |
const values = { |
| 7 |
string: typeof "string", |
| 8 |
number: typeof 123, |
| 9 |
true: typeof true, |
| 10 |
object: typeof {}, |
| 11 |
undefined: typeof undefined, |
| 12 |
function: typeof function () {}, |
| 13 |
symbol: typeof Symbol(), |
| 14 |
bigint: (() => { |
| 15 |
try { |
| 16 |
return eval("typeof 0n"); |
| 17 |
} catch (e) { |
| 18 |
return "bigint"; |
| 19 |
} |
| 20 |
})(), |
| 21 |
}; |
| 22 |
|
| 23 |
for (const name in values) { |
| 24 |
const value = values[name]; |
| 25 |
it(`${name} is valid`, function () { |
| 26 |
const result = createTypeAnnotationBasedOnTypeof(value); |
| 27 |
expect(result).toMatchSnapshot(); |
| 28 |
}); |
| 29 |
} |
| 30 |
|
| 31 |
it("invalid", function () { |
| 32 |
expect(() => |
| 33 |
createTypeAnnotationBasedOnTypeof("thisdoesnotexist"), |
| 34 |
).toThrow(Error); |
| 35 |
}); |
| 36 |
}); |
| 37 |
}); |
| 38 |
}); |