Merge branch 'chore/switch-to-jest' into jest-solutions

This commit is contained in:
Kevin Mulhern 2021-05-18 00:42:57 +01:00
commit a1c56276ea
14 changed files with 7362 additions and 76 deletions

View File

@ -14,7 +14,7 @@ Before you start you should have a few things installed on your machine:
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. 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.
**Note**: Due to the way Jest handles failed tests, it will return an etest.skip 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. **Note**: Due to the way Jest handles failed tests, it may 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.
The first exercise, `helloWorld`, will walk you through the process in-depth. The first exercise, `helloWorld`, will walk you through the process in-depth.

View File

@ -4,19 +4,19 @@ describe('findTheOldest', () => {
test('finds the oldest person!', () => { test('finds the oldest person!', () => {
const people = [ const people = [
{ {
name: 'Carly', name: "Carly",
yearOfBirth: 1942, yearOfBirth: 1942,
yearOfDeath: 1970, yearOfDeath: 1970,
}, },
{ {
name: 'Ray', name: "Ray",
yearOfBirth: 1962, yearOfBirth: 1962,
yearOfDeath: 2011 yearOfDeath: 2011,
}, },
{ {
name: 'Jane', name: "Jane",
yearOfBirth: 1912, yearOfBirth: 1912,
yearOfDeath: 1941 yearOfDeath: 1941,
}, },
] ]
expect(findTheOldest(people).name).toBe('Ray'); expect(findTheOldest(people).name).toBe('Ray');
@ -24,18 +24,18 @@ describe('findTheOldest', () => {
test.skip('finds the oldest person if someone is still living', () => { test.skip('finds the oldest person if someone is still living', () => {
const people = [ const people = [
{ {
name: 'Carly', name: "Carly",
yearOfBirth: 2018, yearOfBirth: 2018,
}, },
{ {
name: 'Ray', name: "Ray",
yearOfBirth: 1962, yearOfBirth: 1962,
yearOfDeath: 2011 yearOfDeath: 2011,
}, },
{ {
name: 'Jane', name: "Jane",
yearOfBirth: 1912, yearOfBirth: 1912,
yearOfDeath: 1941 yearOfDeath: 1941,
}, },
] ]
expect(findTheOldest(people).name).toBe('Ray'); expect(findTheOldest(people).name).toBe('Ray');
@ -43,21 +43,20 @@ describe('findTheOldest', () => {
test.skip('finds the oldest person if the OLDEST is still living', () => { test.skip('finds the oldest person if the OLDEST is still living', () => {
const people = [ const people = [
{ {
name: 'Carly', name: "Carly",
yearOfBirth: 1066, yearOfBirth: 1066,
}, },
{ {
name: 'Ray', name: "Ray",
yearOfBirth: 1962, yearOfBirth: 1962,
yearOfDeath: 2011 yearOfDeath: 2011,
}, },
{ {
name: 'Jane', name: "Jane",
yearOfBirth: 1912, yearOfBirth: 1912,
yearOfDeath: 1941 yearOfDeath: 1941,
}, },
] ]
expect(findTheOldest(people).name).toBe('Carly'); expect(findTheOldest(people).name).toBe('Carly');
}); });
}); });

View File

@ -1,5 +1,5 @@
let <%= title %> = function() { let <%= title %> = function() {
} };
module.exports = <%= title %> module.exports = <%= title %>;

View File

@ -1140,7 +1140,7 @@
"dev": true, "dev": true,
"requires": { "requires": {
"onetime": "^2.0.0", "onetime": "^2.0.0",
"signal-etest.skip": "^3.0.2" "signal-exit": "^3.0.2"
} }
}, },
"string-width": { "string-width": {
@ -1271,9 +1271,9 @@
"merge": "^1.1.3" "merge": "^1.1.3"
} }
}, },
"etest.skip-hook": { "exit-hook": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/etest.skip-hook/-/etest.skip-hook-1.1.1.tgz", "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
"integrity": "sha1-8FyiM7SMBdVP/wd2XfhQfpXAL/g=" "integrity": "sha1-8FyiM7SMBdVP/wd2XfhQfpXAL/g="
}, },
"expand-brackets": { "expand-brackets": {
@ -4225,7 +4225,7 @@
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=", "integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
"requires": { "requires": {
"etest.skip-hook": "^1.0.0", "exit-hook": "^1.0.0",
"onetime": "^1.0.0" "onetime": "^1.0.0"
} }
}, },
@ -4373,9 +4373,9 @@
"integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==",
"dev": true "dev": true
}, },
"signal-etest.skip": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-etest.skip/-/signal-etest.skip-3.0.2.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true "dev": true
}, },
@ -5515,7 +5515,7 @@
"dev": true, "dev": true,
"requires": { "requires": {
"onetime": "^2.0.0", "onetime": "^2.0.0",
"signal-etest.skip": "^3.0.2" "signal-exit": "^3.0.2"
} }
}, },
"string-width": { "string-width": {

View File

@ -15,5 +15,4 @@ describe('getTheTitles', () => {
test('gets titles', () => { test('gets titles', () => {
expect(getTheTitles(books)).toEqual(['Book','Book2']); expect(getTheTitles(books)).toEqual(['Book','Book2']);
}); });
}); });

7364
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,11 +14,11 @@
}, },
"homepage": "https://github.com/TheOdinProject/javascript-exercises#readme", "homepage": "https://github.com/TheOdinProject/javascript-exercises#readme",
"devDependencies": { "devDependencies": {
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"eslint": "^7.26.0", "eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1" "eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"jest-cli": "^26.6.3"
}, },
"scripts": { "scripts": {
"test": "jest" "test": "jest"

View File

@ -19,5 +19,4 @@ describe('palindromes', () => {
test.skip('doesn\'t just always return true', () => { test.skip('doesn\'t just always return true', () => {
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
}); });
}); });

View File

@ -16,6 +16,6 @@ const firstVowelIndex = function(string) {
return string.indexOf(vowels[1]); return string.indexOf(vowels[1]);
} }
return string.indexOf(vowels[0]); return string.indexOf(vowels[0]);
}; };
module.exports = pigLatin; module.exports = pigLatin;

View File

@ -19,7 +19,6 @@ const removeFromArray = function (...args) {
return newArray; return newArray;
}; };
// A simpler, but more advanced way to do it is to use the 'filter' function, // A simpler, but more advanced way to do it is to use the 'filter' function,
// which basically does what we did with the forEach above. // which basically does what we did with the forEach above.

View File

@ -24,7 +24,7 @@ describe('repeatString', () => {
// DO NOT use Math.floor(Math.random() * 1000) in your code, // DO NOT use Math.floor(Math.random() * 1000) in your code,
// this test generates a random number, then passes it into your code with a function parameter. // this test generates a random number, then passes it into your code with a function parameter.
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/courses/web-development-101/lessons/fundamentals-part-3 // If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3
const number = Math.floor(Math.random() * 1000) const number = Math.floor(Math.random() * 1000)
/*The .match(/((hey))/g).length is a regex that will count the number of heys /*The .match(/((hey))/g).length is a regex that will count the number of heys
in the result, which if your function works correctly will equal the number that in the result, which if your function works correctly will equal the number that

View File

@ -19,5 +19,4 @@ describe('snakeCase', () => {
test.skip('works with WTF case', () => { test.skip('works with WTF case', () => {
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome'); expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
}); });
}); });

View File

@ -6,6 +6,7 @@ const ctof = function(c) {
return Math.round(((c * 9/5) + 32) * 10) / 10 return Math.round(((c * 9/5) + 32) * 10) / 10
}; };
module.exports = { module.exports = {
ftoc, ftoc,
ctof ctof