Search⌘ K

Solution Review: Writing a Parameterized Test

Explore how to create parameterized tests in TypeScript to efficiently check that functions return expected results across various inputs. This lesson helps you understand testing techniques that enhance code correctness and maintainability.

We'll cover the following...

Solution

function squared(input: number): number {
    return input * input;
}

describe('this is our test suite', () => {
    [1, 5, 10, 100].forEach(num =>
        it(`should multiply ${num}`, () => {
            const result = squared(num);

            expect(result).toEqual(num * num);
        }));
});
Test using describe function

Explanation

...