Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:14:21+00:00 2026-06-11T19:14:21+00:00

I have a file app.coffee : class TaskList class Task constructor: (@name) -> @status

  • 0

I have a file app.coffee:

class TaskList

class Task
    constructor: (@name) ->
        @status = 'incomplete'
    complete: ->
        if @parent? and @parent.status isnt 'completed'
          throw "Dependent task '#{@parent.name}' is not completed."
        @status = 'complete'
        true
    dependsOn: (@parent) ->
        @parent.child = @
        @status = 'dependent'

# Prepare scope stuff
root = exports ? window
root.TaskList = TaskList
root.Task = Task

and a file called test/taskTest.coffee:

{TaskList, Task} = require '../app'
should = require 'should'

describe 'Task Instance', ->
    task1 = task2 = null
    it 'should have a name', ->
        something = 'asdf'
        something.should.equal 'asdf'
        task1 = new Task 'feed the cat'
        task1.name.should.equal 'feed the cat'
    it 'should be initially incomplete', ->
        task1.status.should.equal 'incomplete'
    it 'should be able to be completed', ->
        task1.complete().should.be.true
        task1.status.should.equal 'complete'
    it 'should be able to be dependent on another task', ->
        task1 = new Task 'wash dishes'
        task2 = new Task 'dry dishes'
        task2.dependsOn task1
        task2.status.should.equal 'dependent'
        task2.parent.should.equal task1
        task1.child.should.equal task2
    it 'should refuse completion it is dependent on an uncompleted task', ->
        (-> task2.complete()).should.throw "Dependent task 'wash dishes' is not completed."

If I run this command in terminal: mocha -r should --compilers coffee:coffee-script -R spec I have a failing test (the final one) saying that it was expecting an exception “Dependent task ‘wash dishes’ is not completed.” but got ‘undefined’.

If I change (-> task2.complete()).should.throw to -> task2.complete().should.throw by removing the parenthesis, the test passes, and fails if I don’t throw the exception. But if I change the exception message to something random, it still passes. Am I doing something wrong? Shouldn’t the test only pass if the message is literally “Dependent task ‘wash dishes’ is not completed.”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:14:22+00:00Added an answer on June 11, 2026 at 7:14 pm

    You are throwing an exception with a string instead of throwing an error object. throw() looks for the latter. So your original code works if you do:

    throw new Error "Dependent task '#{@parent.name}' is not completed."
    

    If something you write in CoffeeScript is producing results that make no sense, try compiling it to js (or pasting the code into try CoffeeScript. You’ll see that:

    -> task2.complete().should.throw "Dependent task 'wash dishes' is not completed."
    

    compiles to:

    (function() {
      return task2.complete().should["throw"]("Dependent task 'wash dishes' is not completed.");
    });
    

    which just defines a function and does not execute it. This explains why changing the string makes no difference. I hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic Node.js+socket.io app, and want to include coffee-script file. It was
I have a file as documentRoot/app/webroot/myFile.php I need to be able to access this
So I built my project and I have a .app file from my BUILD
I have an HTML (App) file that reads another HTML (data) file via jQuery.ajax()
i have a sqlite file in my app. the app is with enterprise certificate
I have a file on my server that's outside of my app directory. It's
I have a main branch with a file called app.js . I made changes
I have to make a peer to peer file sharing app on android platform
I have several small classes that are in a single file in /app/models, similar
If I have a whole bunch of requires in my main app file: require

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.