node-zwave-js/packages/transformers/test/fixtures/testEnum.mts

57 lines
1004 B
TypeScript

/* eslint-disable @typescript-eslint/no-unused-expressions */
import { validateArgs } from "@zwave-js/transformers";
import assert from "node:assert";
enum My {
Foot,
Hand,
Eye,
}
class Test {
@validateArgs()
foo(arg1: My): void {
arg1;
return void 0;
}
@validateArgs({ strictEnums: true })
bar(arg1: My): void {
arg1;
return void 0;
}
}
const test = new Test();
// These should not throw
test.foo(1);
test.foo(My.Hand);
test.foo(My.Eye);
test.foo(10000000 as any);
test.bar(1);
test.bar(My.Hand);
test.bar(My.Eye);
// These should throw
assert.throws(
// @ts-expect-error
() => test.foo("string"),
/arg1 to be a member of enum My, got string "string"/,
);
assert.throws(
// @ts-expect-error
() => test.foo("Hand"),
/arg1 to be a member of enum My, got string "Hand"/,
);
assert.throws(
// @ts-expect-error
() => test.foo(true),
/arg1 to be a member of enum My, got true/,
);
assert.throws(
() => test.bar(10000 as any),
/arg1 to be a member of enum My, got 10000/,
);