Skip to content
Permalink
5d305c3225
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
68 lines (57 sloc) 1.5 KB
'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)
// ARRANGE
const todo = await new ToDo() // DB runs in-memory if no name supplied
// ACT
await todo.add('bread', 3)
const count = await todo.countItems()
// ASSERT
expect(count).toBe(1)
done()
})
test('qty must be a number', async done => {
expect.assertions(1)
const todo = await new ToDo()
await expect( todo.add('bread', 'three') ).rejects.toEqual( Error('the quantity must be a number') )
done()
})
test('duplicates should increase qty', async done => {
expect.assertions(2)
// ARRANGE
const todo = await new ToDo()
// ACT
await todo.add('bread', 4)
await todo.add('bread', 2)
const data = await todo.getAll()
const qty = data[0].qty
// ASSERT (note there are two assertions as stated on line 42)
expect(data).toHaveLength(1)
expect(qty).toEqual(6)
done()
})
})
describe('delete()', () => {
// any tests for the delete() function should be written here
})
describe('getAll()', () => {
// any tests for the getAll() function should be written here
})
describe('clear()', () => {
// any tests for the clear() function should be written here
})