Skip to content
Permalink
Browse files
push
  • Loading branch information
nathwan2 committed Oct 8, 2019
1 parent 6f04e7d commit cae34b63aaecffb72e83cbd0d94a54d460420d13
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
@@ -10,7 +10,16 @@ module.exports.clear = () => {
module.exports.add = (item, qty) => {
qty = Number(qty)
if(isNaN(qty)) throw new Error('the quantity must be a number')
data.push({item: item, qty: qty})
let flag = false
for(let index in data) {
if (data[index].item === item) {
data[index].qty+= qty
flag = true
}
}
if(flag === false) {
data.push({item: item, qty: qty})
}
}

module.exports.getAll = () => {
@@ -41,8 +41,26 @@ describe('add()', () => {
done()
}
})

// New test goes HERE!
test('duplicates should increase qty', async done => {
expect.assertions(2)
try {
// ACT
todo.add('bread', 4)
todo.add('bread', 2)
// ASSERT
const count = todo.countItems()
expect(count).toBe(1)
const data = todo.getAll()
const qty = data[0].qty
expect(qty).toEqual(6)
} catch(err) {
done.fail('test failed')
} finally {
done()
}
})

})

@@ -0,0 +1,19 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'test' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose stack Error: ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
5 verbose cwd /home/anir/foundation
6 error Linux 5.0.0-23-generic
7 error argv "/usr/bin/node" "/usr/bin/npm" "run" "test"
8 error node v8.10.0
9 error npm v3.5.2
10 error path /home/anir/foundation/package.json
11 error code ENOENT
12 error errno -2
13 error syscall open
14 error enoent ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
15 error enoent ENOENT: no such file or directory, open '/home/anir/foundation/package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

0 comments on commit cae34b6

Please sign in to comment.