Testing with TypeScript Quiz (original) (raw)

Why is TypeScript beneficial for writing unit tests?

Which of the following is a correct TypeScript test case?

TypeScript `

import { add } from "./math";

test("should add two numbers", () => { const result: number = add(2, 3); expect(result).toBe(5); });

`

Which testing framework is commonly used with TypeScript?

How do you configure Jest to work with TypeScript?

What is type-safe mocking?

Which library helps create type-safe mocks in TypeScript?

How would you create a type-safe mock using Jest?

TypeScript `

interface UserService { getUser: (id: number) => string; }

const mockUserService: jest.Mocked = { getUser: jest.fn().mockReturnValue("Pranjal"), };

`

Why is mocking important in unit tests?

Which of the following is a valid use case for a test double?

What does the following mock do?

TypeScript `

jest.spyOn(console, "log").mockImplementation(() => {});

`

There are 10 questions to complete.

Take a part in the ongoing discussion