Skip to content

Commit e901090

Browse files
author
xandora
authored
Merge pull request wesbos#1 from xandora/jester-tester
2 parents 42076e7 + 3faff54 commit e901090

25 files changed

+11269
-189
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
.vscode
1+
.vscode
2+
node_modules
3+
package-lock.json
4+
package.json

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ There will eventually be a suggested order of completion, but at this time since
99
## How To Use These Exercises
1010
Before you start you should have a few things installed on your machine:
1111
1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
12-
2. Jasmine. Jasmine is a testing framework for JavaScript. Type `jasmine -v` to check for it. If you need to install it, type `npm install -g jasmine` to do so.
13-
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository)
12+
2. Jest. Jest is a testing framework for JavaScript. To install it, type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
13+
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
1414

15-
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `jasmine exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'xit' compared to 'it'. This is purposeful. After you pass your first 'it', you will change the next 'xit' to an 'it' and test your code again. You'll do this until all conditions are satisfied.
15+
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied.
16+
17+
**Note**: Due to the way Jest handles failed tests, it will return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
1618

1719
The first exercise, `helloWorld`, will walk you through the process in-depth.
1820

caesar/caesar.spec.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
const caesar = require('./caesar')
22

3-
describe('caesar', function() {
4-
it('works with single letters', function() {
5-
expect(caesar('A', 1)).toEqual('B');
6-
});
7-
xit('works with words', function() {
8-
expect(caesar('Aaa', 1)).toEqual('Bbb');
9-
});
10-
xit('works with phrases', function() {
11-
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!');
12-
});
13-
xit('works with negative shift', function() {
14-
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!');
15-
});
16-
xit('wraps', function() {
17-
expect(caesar('Z', 1)).toEqual('A');
18-
});
19-
xit('works with large shift factors', function() {
20-
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!');
21-
});
22-
xit('works with large negative shift factors', function() {
23-
expect(caesar('Hello, World!', -29)).toEqual('Ebiil, Tloia!');
24-
});
3+
test('works with single letters', () => {
4+
expect(caesar('A', 1)).toBe('B');
5+
});
6+
test.skip('works with words', () => {
7+
expect(caesar('Aaa', 1)).toBe('Bbb');
8+
});
9+
test.skip('works with phrases', () => {
10+
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
11+
});
12+
test.skip('works with negative shift', () => {
13+
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
14+
});
15+
test.skip('wraps', () => {
16+
expect(caesar('Z', 1)).toBe('A');
17+
});
18+
test.skip('works with large shift factors', () => {
19+
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
20+
});
21+
test.skip('works with large negative shift factors', () => {
22+
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
2523
});

calculator/calculator.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
function add () {
2-
1+
const add = function() {
2+
33
}
44

5-
function subtract () {
6-
5+
const subtract = function() {
6+
77
}
88

9-
function sum () {
10-
9+
const sum = function() {
10+
1111
}
1212

13-
function multiply () {
14-
13+
const mulitply = function() {
14+
1515
}
1616

17-
function power() {
18-
17+
const power = function() {
18+
1919
}
2020

21-
function factorial() {
22-
21+
const factorial = function() {
22+
2323
}
2424

2525
module.exports = {

calculator/calculator.spec.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
const calculator = require ('./calculator.js');
22

3-
describe('add', function() {
4-
it('adds 0 and 0', function() {
5-
expect(calculator.add(0,0)).toEqual(0);
3+
describe('add', () => {
4+
test('adds 0 and 0', () => {
5+
expect(calculator.add(0,0)).toBe(0);
66
});
77

8-
xit('adds 2 and 2', function() {
9-
expect(calculator.add(2,2)).toEqual(4);
8+
test('adds 2 and 2', () => {
9+
expect(calculator.add(2,2)).toBe(4);
1010
});
1111

12-
xit('adds positive numbers', function() {
13-
expect(calculator.add(2,6)).toEqual(8);
12+
test('adds positive numbers', () => {
13+
expect(calculator.add(2,6)).toBe(8);
1414
});
1515
});
1616

17-
describe('subtract', function() {
18-
xit('subtracts numbers', function() {
19-
expect(calculator.subtract(10,4)).toEqual(6);
17+
describe('subtract', () => {
18+
test('subtracts numbers', () => {
19+
expect(calculator.subtract(10,4)).toBe(6);
2020
});
2121
});
2222

23-
describe('sum', function() {
24-
xit('computes the sum of an empty array', function() {
25-
expect(calculator.sum([])).toEqual(0);
23+
describe('sum', () => {
24+
test('computes the sum of an empty array', () => {
25+
expect(calculator.sum([])).toBe(0);
2626
});
2727

28-
xit('computes the sum of an array of one number', function() {
29-
expect(calculator.sum([7])).toEqual(7);
28+
test('computes the sum of an array of one number', () => {
29+
expect(calculator.sum([7])).toBe(7);
3030
});
3131

32-
xit('computes the sum of an array of two numbers', function() {
33-
expect(calculator.sum([7,11])).toEqual(18);
32+
test('computes the sum of an array of two numbers', () => {
33+
expect(calculator.sum([7,11])).toBe(18);
3434
});
3535

36-
xit('computes the sum of an array of many numbers', function() {
37-
expect(calculator.sum([1,3,5,7,9])).toEqual(25);
36+
test('computes the sum of an array of many numbers', () => {
37+
expect(calculator.sum([1,3,5,7,9])).toBe(25);
3838
});
3939
});
4040

41-
describe('multiply', function() {
42-
xit('multiplies two numbers', function() {
43-
expect(calculator.multiply([2,4])).toEqual(8);
41+
describe('multiply', () => {
42+
test('multiplies two numbers', () => {
43+
expect(calculator.multiply([2,4])).toBe(8);
4444
});
4545

46-
xit('multiplies several numbers', function() {
47-
expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120);
46+
test('multiplies several numbers', () => {
47+
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
4848
});
4949
});
5050

51-
describe('power', function() {
52-
xit('raises one number to the power of another number', function() {
53-
expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64
51+
describe('power', () => {
52+
test('raises one number to the power of another number', () => {
53+
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
5454
});
5555
});
5656

57-
describe('factorial', function() {
58-
xit('computes the factorial of 0', function() {
59-
expect(calculator.factorial(0)).toEqual(1); // 0! = 1
57+
describe('factorial', () => {
58+
test.skip('computes the factorial of 0', () => {
59+
expect(calculator.factorial(0)).toBe(1); // 0! = 1
6060
});
6161

62-
xit('computes the factorial of 1', function() {
63-
expect(calculator.factorial(1)).toEqual(1);
62+
test.skip('computes the factorial of 1', () => {
63+
expect(calculator.factorial(1)).toBe(1);
6464
});
6565

66-
xit('computes the factorial of 2', function() {
67-
expect(calculator.factorial(2)).toEqual(2);
66+
test.skip('computes the factorial of 2', () => {
67+
expect(calculator.factorial(2)).toBe(2);
6868
});
6969

70-
xit('computes the factorial of 5', function() {
71-
expect(calculator.factorial(5)).toEqual(120);
70+
test.skip('computes the factorial of 5', () => {
71+
expect(calculator.factorial(5)).toBe(120);
7272
});
7373

74-
xit('computes the factorial of 10', function() {
75-
expect(calculator.factorial(10)).toEqual(3628800);
74+
test.skip('computes the factorial of 10', () => {
75+
expect(calculator.factorial(10)).toBe(3628800);
7676
});
7777
});

fibonacci/fibonacci.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const fibonacci = function() {
22

33
}
44

5-
module.exports = fibonacci
5+
module.exports = fibonacci;

fibonacci/fibonacci.spec.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
const fibonacci = require('./fibonacci')
22

3-
describe('fibonacci', function() {
4-
it('works', function() {
5-
expect(fibonacci(4)).toEqual(3);
3+
describe('fibonacci', () => {
4+
test('4th fibonacci number is 3', () => {
5+
expect(fibonacci(4)).toBe(3);
66
});
7-
xit('works', function() {
8-
expect(fibonacci(6)).toEqual(8);
7+
test.skip('6th fibonacci number is 8', () => {
8+
expect(fibonacci(6)).toBe(8);
99
});
10-
xit('works', function() {
11-
expect(fibonacci(10)).toEqual(55);
10+
test.skip('10th fibonacci number is 55', () => {
11+
expect(fibonacci(10)).toBe(55);
1212
});
13-
xit('works', function() {
14-
expect(fibonacci(15)).toEqual(610);
13+
test.skip('15th fibonacci number is 610', () => {
14+
expect(fibonacci(15)).toBe(610);
1515
});
16-
xit('works', function() {
17-
expect(fibonacci(25)).toEqual(75025);
16+
test.skip('25th fibonacci number is 75025', () => {
17+
expect(fibonacci(25)).toBe(75025);
1818
});
19-
xit('doesn\'t accept negatives', function() {
20-
expect(fibonacci(-25)).toEqual("OOPS");
19+
test.skip('doesn\'t accept negatives', () => {
20+
expect(fibonacci(-25)).toBe("OOPS");
2121
});
22-
xit('DOES accept strings', function() {
23-
expect(fibonacci("1")).toEqual(1);
22+
test.skip('DOES accept strings', () => {
23+
expect(fibonacci("1")).toBe(1);
2424
});
25-
xit('DOES accept strings', function() {
26-
expect(fibonacci("2")).toEqual(1);
25+
test.skip('DOES accept strings', () => {
26+
expect(fibonacci("2")).toBe(1);
2727
});
28-
xit('DOES accept strings', function() {
29-
expect(fibonacci("8")).toEqual(21);
28+
test.skip('DOES accept strings', () => {
29+
expect(fibonacci("8")).toBe(21);
3030
});
3131
});

findTheOldest/findTheOldest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let findTheOldest = function() {
1+
const findTheOldest = function() {
22

33
}
44

findTheOldest/findTheOldest.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
let findTheOldest = require('./findTheOldest')
1+
const findTheOldest = require('./findTheOldest')
22

3-
describe('findTheOldest', function() {
4-
it('finds the oldest person!', function() {
3+
describe('findTheOldest', () => {
4+
test('finds the oldest person!', () => {
55
const people = [
66
{
77
name: 'Carly',
@@ -19,9 +19,9 @@ describe('findTheOldest', function() {
1919
yearOfDeath: 1941
2020
},
2121
]
22-
expect(findTheOldest(people).name).toEqual('Ray');
22+
expect(findTheOldest(people).name).toBe('Ray');
2323
});
24-
xit('finds the oldest person if someone is still living', function() {
24+
test.skip('finds the oldest person if someone is still living', () => {
2525
const people = [
2626
{
2727
name: 'Carly',
@@ -38,9 +38,9 @@ describe('findTheOldest', function() {
3838
yearOfDeath: 1941
3939
},
4040
]
41-
expect(findTheOldest(people).name).toEqual('Ray');
41+
expect(findTheOldest(people).name).toBe('Ray');
4242
});
43-
xit('finds the oldest person if the OLDEST is still living', function() {
43+
test.skip('finds the oldest person if the OLDEST is still living', () => {
4444
const people = [
4545
{
4646
name: 'Carly',
@@ -57,7 +57,7 @@ describe('findTheOldest', function() {
5757
yearOfDeath: 1941
5858
},
5959
]
60-
expect(findTheOldest(people).name).toEqual('Carly');
60+
expect(findTheOldest(people).name).toBe('Carly');
6161
});
6262

6363
});

getTheTitles/getTheTitles.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let getTheTitles = require('./getTheTitles')
1+
const getTheTitles = require('./getTheTitles')
22

3-
describe('getTheTitles', function() {
3+
describe('getTheTitles', () => {
44
const books = [
55
{
66
title: 'Book',
@@ -12,8 +12,8 @@ describe('getTheTitles', function() {
1212
}
1313
]
1414

15-
it('gets titles', function() {
16-
expect(getTheTitles(books)).toEqual(['Book','Book2']);
15+
test('gets titles', () => {
16+
expect(getTheTitles(books)).toBe(['Book','Book2']);
1717
});
1818

1919
});

0 commit comments

Comments
 (0)