|
| 1 | +// npm install --save-dev jest |
| 2 | +// We name the file with the ending .test.js |
| 3 | +// To run the program: npx jest .\Sac-Corts.test.js |
| 4 | + |
| 5 | +function addition(a: number, b: number): number { |
| 6 | + return a + b; |
| 7 | +} |
| 8 | + |
| 9 | +test('addition 1 + 2 should be 3', () => { |
| 10 | + expect(addition(1, 2)).toBe(3); |
| 11 | +}); |
| 12 | + |
| 13 | +test('addition 3 + 7 should be 10', () => { |
| 14 | + expect(addition(3, 7)).toBe(10); |
| 15 | +}); |
| 16 | + |
| 17 | +// ** Extra Exercise ** // |
| 18 | +interface Data { |
| 19 | + name: string; |
| 20 | + age: string; |
| 21 | + birthdate: string; |
| 22 | + programmingLanguages: string[]; |
| 23 | +} |
| 24 | + |
| 25 | +const data: Data = { |
| 26 | + name: "Isaac", |
| 27 | + age: "22", |
| 28 | + birthdate: "2001-10-21", |
| 29 | + programmingLanguages: ["JavaScript", "Python"] |
| 30 | +}; |
| 31 | + |
| 32 | +test('It should have all the necessary keys', () => { |
| 33 | + expect(data).toHaveProperty('name'); |
| 34 | + expect(data).toHaveProperty('age'); |
| 35 | + expect(data).toHaveProperty('birthdate'); |
| 36 | + expect(data).toHaveProperty('programmingLanguages'); |
| 37 | +}); |
| 38 | + |
| 39 | +test('It should have the correct data', () => { |
| 40 | + expect(data.name).toBe("Isaac"); |
| 41 | + expect(data.age).toBe("22"); |
| 42 | + expect(data.birthdate).toBe("2001-10-21"); |
| 43 | + expect(data.programmingLanguages).toEqual(["JavaScript", "Python"]); |
| 44 | +}); |
0 commit comments