Added feature of checking if task added is neither a string nor a Task object. But I also discovered that the error thrown is not checked properly.
This commit is contained in:
parent
d7efe472f3
commit
a286e23fdf
|
@ -17,10 +17,12 @@ class TaskList
|
||||||
@tasks = []
|
@tasks = []
|
||||||
@length = 0
|
@length = 0
|
||||||
add: (@name) ->
|
add: (@name) ->
|
||||||
|
unless typeof @name is 'string' or @name instanceof Task
|
||||||
|
throw "Here's an error"
|
||||||
if typeof @name is 'string'
|
if typeof @name is 'string'
|
||||||
task = new Task 'take out garbage'
|
task = new Task 'take out garbage'
|
||||||
@tasks.push task
|
@tasks.push task
|
||||||
else
|
if @name instanceof Task
|
||||||
@tasks.push @name
|
@tasks.push @name
|
||||||
@length++
|
@length++
|
||||||
remove: (task) ->
|
remove: (task) ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
chai = require 'chai'
|
chai = require 'chai'
|
||||||
chai.should()
|
should = chai.should()
|
||||||
expect = chai.expect
|
expect = chai.expect
|
||||||
|
|
||||||
{TaskList, Task} = require '../src/task'
|
{TaskList, Task} = require '../src/task'
|
||||||
|
@ -36,7 +36,8 @@ describe 'Task instance', ->
|
||||||
task2.status.should.equal 'dependent'
|
task2.status.should.equal 'dependent'
|
||||||
task2.parent.should.equal task1
|
task2.parent.should.equal task1
|
||||||
task1.child.should.equal task2
|
task1.child.should.equal task2
|
||||||
-> task2.complete().should.throw "Dependent task 'wash dishes' is not completed."
|
#-> task2.complete().should.throw "Dependent task 'wash dishes' is not completed."
|
||||||
|
(-> task2.complete()).should.throw "Dependent task 'wash dishes' is not completed."
|
||||||
|
|
||||||
describe 'TaskList', ->
|
describe 'TaskList', ->
|
||||||
taskList = null
|
taskList = null
|
||||||
|
@ -90,3 +91,8 @@ describe 'TaskList', ->
|
||||||
"""
|
"""
|
||||||
|
|
||||||
taskList.print().should.equal desiredOutput
|
taskList.print().should.equal desiredOutput
|
||||||
|
it "throws error if anything but strings or task is added", ->
|
||||||
|
taskList = new TaskList
|
||||||
|
Error = "This is an error"
|
||||||
|
(-> taskList.add(123123)).should.throw(Error)
|
||||||
|
#assert(expression, message, negateMessage, expected, actual)
|
||||||
|
|
Loading…
Reference in a new issue