-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a typescript test (not just a compile test) for enums
- Loading branch information
1 parent
c938efa
commit 9c6f801
Showing
2 changed files
with
28 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |