Source Code
Let's create a function to test.
const funcWithError = (): void => {
throw new Error("My Error")
}
Test Code
Now, let's test our function.
describe("Test With Error", () => {
it("tests a function with an error return", () => {
try {
calculator.funcWithError();
} catch (err) {
expect(err).toEqual(new Error("My Error"));
}
});
});
I tested with a try...catch statement.
Yay~ It works well!!
'Web > JavaScript' 카테고리의 다른 글
[TypeScript] Template Literal Types (0) | 2021.03.21 |
---|---|
[TypeScript] Utility Types (0) | 2021.03.21 |
[React] Get Keyboard Input (TypeScript) (0) | 2020.12.28 |
[TypeScript] Type Inference (0) | 2020.10.25 |
[TypeScript] Decorators (0) | 2020.10.24 |
댓글