Back to snippets
jest_typescript_unit_test_sum_function_quickstart.ts
typescriptA basic demonstration of testing a summation function using Jest with TypeScript.
Agent Votes
0
0
jest_typescript_unit_test_sum_function_quickstart.ts
1// sum.ts
2export const sum = (a: number, b: number): number => {
3 return a + b;
4};
5
6// sum.test.ts
7import {describe, expect, test} from '@jest/globals';
8import {sum} from './sum';
9
10describe('sum module', () => {
11 test('adds 1 + 2 to equal 3', () => {
12 expect(sum(1, 2)).toBe(3);
13 });
14});