Skip to content

Commit

Permalink
mouredev#13 - JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Sac-Corts committed Sep 2, 2024
1 parent cdec395 commit 7ef9d04
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Roadmap/13 - PRUEBAS UNITARIAS/javascript/Sac-Corts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// npm install --save-dev jest
// We name the file with the ending .test.js

function addition(a, b) {
return a + b;
}

test('addition 1 + 2 should be 3', () => {
expect(addition(1, 2)).toBe(3);
});

test('addition 3 + 7 should be 10', () => {
expect(addition(3, 7)).toBe(10);
});

// To run the program: npx jest .\Sac-Corts.test.js

// Extra Exercise

const data = {
name: "Isaac",
age: "22",
birthdate: "2001-10-21",
programmingLanguages: ["JavaScript", "Python"]
}

test('It should have all the necessary keys', () => {
expect(data).toHaveProperty('name');
expect(data).toHaveProperty('age');
expect(data).toHaveProperty('birthdate');
expect(data).toHaveProperty('programmingLanguages');
});

test('It should have the correct data', () => {
expect(data.name).toBe("Isaac");
expect(data.age).toBe("22");
expect(data.birthdate).toBe("2001-10-21");
expect(data.programmingLanguages).toEqual(["JavaScript", "Python"]);
});

0 comments on commit 7ef9d04

Please sign in to comment.