Skip to content
Permalink
Browse files
Done some test runs
  • Loading branch information
kluzikp committed Sep 27, 2019
1 parent a029771 commit 239f61fbd00eb4f12252703dc83cd81462ccaeb6
Show file tree
Hide file tree
Showing 2 changed files with 27 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 i in data){
if (data[i].item === item){
data[i].qty+=qty
flag = true
}
}
if(flag === false ) {
data.push({item: item, qty: qty})
}
}

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

test('same item must combine', async done => {
expect.assertions(2)
try {
//act
todo.add('bread', 3)
todo.add('bread', 5)
//assert
expect(todo.countItems()).toBe(1)
const data = todo.getAll()
const qty = data[0].qty
expect(qty).toEqual(8)
} catch(err) {
done.fail(err)
} finally {
done()
}
})
// New test goes HERE!

})

0 comments on commit 239f61f

Please sign in to comment.