From 9c6f801c95545f76bd9840b840fa919f414120a0 Mon Sep 17 00:00:00 2001 From: Thomas Etter Date: Sat, 2 Dec 2023 18:32:33 +0100 Subject: [PATCH] Add a typescript test (not just a compile test) for enums --- crates/typescript-tests/jest.config.cjs | 1 - crates/typescript-tests/src/enums.ts | 41 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/crates/typescript-tests/jest.config.cjs b/crates/typescript-tests/jest.config.cjs index 670569739448..2db7cd7178dc 100644 --- a/crates/typescript-tests/jest.config.cjs +++ b/crates/typescript-tests/jest.config.cjs @@ -8,7 +8,6 @@ module.exports = { // TODO: migrate all test files and remove this testPathIgnorePatterns: [ ".*/src/custom_section.ts$", - ".*/src/enums.ts$", ".*/src/getters_setters.ts$", ".*/src/inspectable.ts$", ".*/src/memory.ts$", diff --git a/crates/typescript-tests/src/enums.ts b/crates/typescript-tests/src/enums.ts index ea246fc847a4..e5d73b1781cc 100644 --- a/crates/typescript-tests/src/enums.ts +++ b/crates/typescript-tests/src/enums.ts @@ -1,13 +1,28 @@ -import * as wbg from '../pkg/typescript_tests'; - -const a1: wbg.Foo = wbg.Foo.A; -const a2: wbg.Foo.A = wbg.Foo.A; -const a3: wbg.Foo.A = 1; -const b1: wbg.Foo = wbg.Foo.B; -const b2: wbg.Foo.B = wbg.Foo.B; -const b3: wbg.Foo.B = 3; - -const fn_expects_enum: (_: wbg.Foo) => void = wbg.fn_expects_enum; -const fn_returns_enum: () => wbg.Foo = wbg.fn_returns_enum; -const fn_expects_option_enum: (_?: wbg.Foo) => void = wbg.fn_expects_option_enum; -const fn_returns_option_enum: () => wbg.Foo | undefined = wbg.fn_returns_option_enum; +import * as wbg from "../pkg/typescript_tests"; +import { expect, jest, test } from "@jest/globals"; + +test("construction", () => { + const a1: wbg.Foo = wbg.Foo.A; + const a2: wbg.Foo.A = wbg.Foo.A; + expect(a1).toStrictEqual(a2); + const a3: wbg.Foo.A = 1; + expect(a1).toStrictEqual(a3); + + const b1: wbg.Foo = wbg.Foo.B; + const b2: wbg.Foo.B = wbg.Foo.B; + expect(b1).toStrictEqual(b2); + const b3: wbg.Foo.B = 3; + expect(b1).toStrictEqual(b3); + expect(() => { return a1 as wbg.Foo != b1 }).toBeTruthy(); +}); + +test("function calls", () => { + const fn_expects_enum: (_: wbg.Foo) => void = wbg.fn_expects_enum; + const fn_returns_enum: () => wbg.Foo = wbg.fn_returns_enum; + const fn_expects_option_enum: (_?: wbg.Foo) => void = wbg.fn_expects_option_enum; + const fn_returns_option_enum: () => wbg.Foo | undefined = wbg.fn_returns_option_enum; + + fn_expects_enum(wbg.Foo.B); + expect(fn_returns_enum()).toStrictEqual(wbg.Foo.A); + expect(fn_returns_option_enum()).toStrictEqual(wbg.Foo.A); +});