From e53a7e8f97ea80ffea40b5237c608f2347623dfa Mon Sep 17 00:00:00 2001 From: Jim Cramer Date: Fri, 25 Jan 2019 12:15:55 +0100 Subject: [PATCH 1/2] Updates README to include required User Settings --- Week1/README.md | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Week1/README.md b/Week1/README.md index f7617fad6..a2f5bbd59 100644 --- a/Week1/README.md +++ b/Week1/README.md @@ -25,17 +25,42 @@ In week one we will discuss the following topics: - Live Server - Bracket Pair Colorizer -2. Install the ESLint tool globally by issuing the following command from the command line: +2. Modify the VSCode User Settings to include the settings listed below. If a particular setting is already present in your User Settings, make sure that the setting value listed below is used and change it if necessary. + + To open your user and workspace settings, use the following VS Code menu command: + + - On Windows/Linux - **File** > **Preferences** > **Settings** + - On macOS - **Code** > **Preferences** > **Settings** + + Then, click on the `{ }` button in the top-right corner of the settings screen to access the settings in JSON format. + + ```json + /// Place your settings in this file to overwrite the default settings + { + "editor.detectIndentation": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.minimap.enabled": false, + "editor.renderIndentGuides": true, + "editor.tabSize": 2, + "files.autoSave": "onFocusChange", + "prettier.printWidth": 100, + "prettier.singleQuote": true, + "prettier.trailingComma": "es5" + } + ``` + +3. Install the ESLint CLI tool globally by issuing the following command from the command line: ``` - npm install -g eslint + npm install -g eslint-cli ``` -3. Fork this repository (i.e., **JavaScript2**) and clone your fork to your laptop. +4. Fork this repository (i.e., **JavaScript2**) and clone your fork to your laptop. -4. Open the `JavaScript2` folder from the cloned repository in VSCode. +5. Open the `JavaScript2` folder from the cloned repository in VSCode. -5. Open a terminal window in VSCode and type the following command: +6. Open a terminal window in VSCode and type the following command: ``` npm install From 499d75798eb172e0fcbd4fa1f333a9aebec282c5 Mon Sep 17 00:00:00 2001 From: Jim Cramer Date: Fri, 25 Jan 2019 12:16:10 +0100 Subject: [PATCH 2/2] Improves unit tests --- Week2/test/maartjes-work.test.js | 10 +++--- Week2/test/map-filter.test.js | 8 +++-- Week3/test/step2-1.test.js | 8 +++-- Week3/test/step2-2.test.js | 22 +++++++----- Week3/test/step2-3.test.js | 57 ++++++++++++++++++++++++-------- Week3/test/step2-4.test.js | 21 +++++++++--- Week3/test/step2-5.test.js | 8 +++-- Week3/test/step2-6.test.js | 7 ++-- Week3/test/step3-bonus.test.js | 12 ++++--- Week3/test/step3.test.js | 16 ++++++--- 10 files changed, 118 insertions(+), 51 deletions(-) diff --git a/Week2/test/maartjes-work.test.js b/Week2/test/maartjes-work.test.js index 59225a53a..ab6bc2a44 100644 --- a/Week2/test/maartjes-work.test.js +++ b/Week2/test/maartjes-work.test.js @@ -1,7 +1,9 @@ const { maartjesTasks, maartjesHourlyRate, computeEarnings } = require(`../homework/maartjes-work`); -test('maartjes_work.js', () => { - const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); - const result = earnings.toFixed(2); - expect(result).toBe('373.33'); +describe('maartjes_work', () => { + test('earnings rounded to euro cents', () => { + const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); + const result = earnings.toFixed(2); + expect(result).toBe('373.33'); + }); }); diff --git a/Week2/test/map-filter.test.js b/Week2/test/map-filter.test.js index a3f613a8b..e4cb83906 100644 --- a/Week2/test/map-filter.test.js +++ b/Week2/test/map-filter.test.js @@ -1,6 +1,8 @@ const { myNumbers, doubleOddNumbers } = require(`../homework/map-filter`); -test('map_filter.js', () => { - const result = doubleOddNumbers(myNumbers); - expect(result).toEqual([2, 6]); +describe('map_filter', () => { + test('result -> [2, 6]', () => { + const result = doubleOddNumbers(myNumbers); + expect(result).toEqual([2, 6]); + }); }); diff --git a/Week3/test/step2-1.test.js b/Week3/test/step2-1.test.js index 9f6b29c10..070706181 100644 --- a/Week3/test/step2-1.test.js +++ b/Week3/test/step2-1.test.js @@ -2,7 +2,9 @@ const foo = require('../homework/step2-1'); const mockFn = jest.fn(() => undefined); -test('1-step3.js', () => { - foo(mockFn); - expect(mockFn.mock.calls.length).toBe(1); +describe('step2-1', () => { + test('foo calls func', () => { + foo(mockFn); + expect(mockFn.mock.calls.length).toBe(1); + }); }); diff --git a/Week3/test/step2-2.test.js b/Week3/test/step2-2.test.js index 71cd7f424..8e0be47cc 100644 --- a/Week3/test/step2-2.test.js +++ b/Week3/test/step2-2.test.js @@ -3,14 +3,20 @@ const threeFive = require('../homework/step2-2'); const mockSayThree = jest.fn(() => undefined); const mockSayFive = jest.fn(() => undefined); -test('2-step3.js', () => { - threeFive(10, 15, mockSayThree, mockSayFive); +describe('step2-2', () => { + test('12 and 15 divisible by 3', () => { + threeFive(10, 15, mockSayThree, () => undefined); - expect(mockSayThree.mock.calls.length).toBe(2); - expect(mockSayThree.mock.calls[0][0]).toBe(12); - expect(mockSayThree.mock.calls[1][0]).toBe(15); + expect(mockSayThree.mock.calls.length).toBe(2); + expect(mockSayThree.mock.calls[0][0]).toBe(12); + expect(mockSayThree.mock.calls[1][0]).toBe(15); + }); - expect(mockSayFive.mock.calls.length).toBe(2); - expect(mockSayFive.mock.calls[0][0]).toBe(10); - expect(mockSayFive.mock.calls[1][0]).toBe(15); + test('10 and 15 divisible by 5', () => { + threeFive(10, 15, () => undefined, mockSayFive); + + expect(mockSayFive.mock.calls.length).toBe(2); + expect(mockSayFive.mock.calls[0][0]).toBe(10); + expect(mockSayFive.mock.calls[1][0]).toBe(15); + }); }); diff --git a/Week3/test/step2-3.test.js b/Week3/test/step2-3.test.js index 11d29b16c..387562660 100644 --- a/Week3/test/step2-3.test.js +++ b/Week3/test/step2-3.test.js @@ -4,37 +4,68 @@ const { repeatStringNumTimesWithDoWhile } = require('../homework/step2-3'); -describe('1-step3.js', () => { - test('for-loop', () => { - let result = repeatStringNumTimesWithFor('abc', 3); +describe('step2-3 with for-loop', () => { + test('num = 3', () => { + const result = repeatStringNumTimesWithFor('abc', 3); expect(result).toBe('abcabcabc'); + }); - result = repeatStringNumTimesWithFor('abc', 1); + test('num = 1', () => { + const result = repeatStringNumTimesWithFor('abc', 1); expect(result).toBe('abc'); + }); - result = repeatStringNumTimesWithFor('abc', -2); + test('num = -2', () => { + const result = repeatStringNumTimesWithFor('abc', -2); expect(result).toBe(''); }); - test('while-loop', () => { - let result = repeatStringNumTimesWithWhile('abc', 3); + test('num = 0', () => { + const result = repeatStringNumTimesWithFor('abc', 0); + expect(result).toBe(''); + }); +}); + +describe('step2-3 with while-loop', () => { + test('num = 3', () => { + const result = repeatStringNumTimesWithWhile('abc', 3); expect(result).toBe('abcabcabc'); + }); - result = repeatStringNumTimesWithFor('abc', 1); + test('num = 1', () => { + const result = repeatStringNumTimesWithWhile('abc', 1); expect(result).toBe('abc'); + }); - result = repeatStringNumTimesWithFor('abc', -2); + test('num = 0', () => { + const result = repeatStringNumTimesWithWhile('abc', 0); expect(result).toBe(''); }); - test('do-while-loop', () => { - let result = repeatStringNumTimesWithDoWhile('abc', 3); + test('num = -2', () => { + const result = repeatStringNumTimesWithWhile('abc', -2); + expect(result).toBe(''); + }); +}); + +describe('step2-3 with do-while-loop', () => { + test('num = 3', () => { + const result = repeatStringNumTimesWithDoWhile('abc', 3); expect(result).toBe('abcabcabc'); + }); - result = repeatStringNumTimesWithFor('abc', 1); + test('num = 1', () => { + const result = repeatStringNumTimesWithDoWhile('abc', 1); expect(result).toBe('abc'); + }); + + test('num = 0', () => { + const result = repeatStringNumTimesWithDoWhile('abc', 0); + expect(result).toBe(''); + }); - result = repeatStringNumTimesWithFor('abc', -2); + test('num = -2', () => { + const result = repeatStringNumTimesWithDoWhile('abc', -2); expect(result).toBe(''); }); }); diff --git a/Week3/test/step2-4.test.js b/Week3/test/step2-4.test.js index 924564383..af21ca4cf 100644 --- a/Week3/test/step2-4.test.js +++ b/Week3/test/step2-4.test.js @@ -1,8 +1,19 @@ const hound = require('../homework/step2-4'); -test('4-step3', () => { - expect(typeof hound).toBe('object'); - expect(typeof hound.name).toBe('string'); - expect(typeof hound.color).toBe('string'); - expect(typeof hound.numLegs).toBe('number'); +describe('step2-4', () => { + test('hound to be an object', () => { + expect(typeof hound).toBe('object'); + }); + + test('hound.name to be a string', () => { + expect(typeof hound.name).toBe('string'); + }); + + test('hound.color to be a string', () => { + expect(typeof hound.color).toBe('string'); + }); + + test('hound.numLegs to be a number', () => { + expect(typeof hound.numLegs).toBe('number'); + }); }); diff --git a/Week3/test/step2-5.test.js b/Week3/test/step2-5.test.js index e87138099..19c770412 100644 --- a/Week3/test/step2-5.test.js +++ b/Week3/test/step2-5.test.js @@ -1,6 +1,8 @@ const multiplyAll = require('../homework/step2-5'); -test('5-step3.js', () => { - const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]); - expect(result).toBe(5040); +describe('step2-5', () => { + test('result to be product of array elements', () => { + const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]); + expect(result).toBe(5040); + }); }); diff --git a/Week3/test/step2-6.test.js b/Week3/test/step2-6.test.js index ee742d527..c2ccd55d8 100644 --- a/Week3/test/step2-6.test.js +++ b/Week3/test/step2-6.test.js @@ -1,3 +1,4 @@ +/* eslint-disable no-return-assign, dot-notation */ const { printArray2d, printArray3d } = require('../homework/step2-6'); const arr2d = [[1, 2], [3, 4], [5, 6]]; @@ -6,18 +7,18 @@ const expected2d = [1, 2, 3, 4, 5, 6].join(''); const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; const expected3d = [1, 2, 3, 4, 5, 6, 7, 8].join(''); -describe('6-step3.js', () => { +describe('step2-6', () => { let outputData; const storeLog = (...inputs) => (outputData += inputs.join(' ')); - test('printArray2d', () => { + test('printArray2d -> 1, 2, 3, 4, 5, 6', () => { outputData = ''; console['log'] = jest.fn(storeLog); printArray2d(arr2d); expect(outputData).toBe(expected2d); }); - test('printArray2d', () => { + test('printArray3d -> 1, 2, 3, 4, 5, 6, 7, 8', () => { outputData = ''; console['log'] = jest.fn(storeLog); printArray3d(arr3d); diff --git a/Week3/test/step3-bonus.test.js b/Week3/test/step3-bonus.test.js index a53764e06..4fdfb0111 100644 --- a/Week3/test/step3-bonus.test.js +++ b/Week3/test/step3-bonus.test.js @@ -1,8 +1,10 @@ const makeUnique = require(`../homework/step3-bonus`); -test('step4-bonus', () => { - const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; - const expected = ['a', 'b', 'c', 'd', 'e', 'f']; - const result = makeUnique(values); - expect(result).toEqual(expected); +describe('step3-bonus', () => { + test('array should not contain duplicates', () => { + const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; + const expected = ['a', 'b', 'c', 'd', 'e', 'f']; + const result = makeUnique(values); + expect(result).toEqual(expected); + }); }); diff --git a/Week3/test/step3.test.js b/Week3/test/step3.test.js index 5bdb657ef..c75f489c2 100644 --- a/Week3/test/step3.test.js +++ b/Week3/test/step3.test.js @@ -1,7 +1,15 @@ const createBase = require(`../homework/step3`); -test('step4.js', () => { - const addSix = createBase(6); - const result = addSix(10); - expect(result).toBe(16); +describe('step3', () => { + test('base = 6', () => { + const addSix = createBase(6); + const result = addSix(10); + expect(result).toBe(16); + }); + + test('base = 10', () => { + const addTen = createBase(10); + const result = addTen(10); + expect(result).toBe(20); + }); });