Skip to content
Permalink
Browse files
added base code for todo
  • Loading branch information
aa7401 committed Sep 13, 2019
1 parent 433c905 commit 34b43ed
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 6 deletions.
@@ -1,14 +1,36 @@

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceFolder}/exercises/12_spa/books/node_modules/.bin/jest",
"name": "Jest All",
"program": "${workspaceFolder}/exercises/07_unit_testing/todo/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/exercises/07_unit_testing/todo/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/exercises/07_unit_testing/todo/node_modules/jest/bin/jest",
"args": [
"-i"
]
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/exercises/07_unit_testing/todo/node_modules/jest/bin/jest",
}
}
]
}
}
@@ -4,3 +4,11 @@
In this worksheet you will learn the basics of using automated tests to improve the quality of your code.

Before you start you need to pull any _upstream changes_. Detailed instructions can be found in the **Setup** lab.

We will be using both the Jest commandline tools and the integrated unit testing tools in Visual Studio Code, you should be familiar with both approaches.

## Visual Studio Code Extensions

One of the powerful features of VS Code is its support for **Extensions** which allow you to add additional capabilities to the editor.

You should start by checking that the following VS Code Extensions are installed and install them if missing.
@@ -0,0 +1,36 @@

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
@@ -0,0 +1,26 @@

'use strict';

module.exports = {
displayName: 'test',
verbose: true,
collectCoverage: true,
testPathIgnorePatterns: [
'/node_modules/',
'/__tests__/fixtures/',
],
}

// "jest": {
// "testEnvironment": "node",
// "verbose": true,
// "collectCoverage": true,
// "coverageThreshold": {
// "global": {
// "branches": 0,
// "functions": 0,
// "lines": 0,
// "statements": 0
// }
// }
// }
@@ -8,6 +8,7 @@ module.exports.clear = () => {
}

module.exports.add = (item, qty) => {
if(typeof qty !== 'number') throw new Error('qty must be a number')
data.push({item: item, qty: qty})
}

@@ -21,3 +22,7 @@ module.exports.delete = key => {
console.log(`delete key ${key}`)
return
}

module.exports.countItems = () => data.length

module.exports.count = data.length
@@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"linter": "node_modules/.bin/eslint .",
"test": "node_modules/.bin/jest --coverage --runInBand"
},
"author": "",
"license": "ISC",
@@ -17,5 +18,13 @@
"koa-router": "^7.4.0",
"koa-static": "^5.0.0",
"koa-views": "^6.2.1"
},
"devDependencies": {
"jest": "^24.9.0"
},
"jest": {
"projects": [
"<rootDir>/jest-test.config.js"
]
}
}
@@ -0,0 +1,6 @@

Install

1. coverage-gutters
2. jest
3. test-explorer
@@ -0,0 +1,44 @@

'use strict'

const todo = require('../modules/todo.js')

beforeAll( async() => {
// stuff to do before any of the tests run
})

afterAll( async() => {
// runs after all the tests have completed
})

describe('add()', () => {
// block of tests
beforeEach( async() => {
todo.clear()
})
afterEach( async() => {
// runs after each test completes
})
test('add a single item', async done => {
expect.assertions(1)
try {
todo.add('bread', 3)
expect(todo.countItems()).toBe(1)
} catch(err) {
done.fail(err)
} finally {
done()
}
})
test('qty must be a number', async done => {
expect.assertions(1)
try {
todo.add('bread', 'three')
done.fail('test failed')
} catch(err) {
expect(err.message).toBe('qty must be a number')
} finally {
done()
}
})
})

0 comments on commit 34b43ed

Please sign in to comment.