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 8367759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:14:22+00:00 2026-06-09T13:14:22+00:00

Please consider I have the following CoffeeScript code: class Foobar test: (path) -> fs

  • 0

Please consider I have the following CoffeeScript code:

class Foobar
    test: (path) ->
        fs = require 'fs'
        fs.readFile path, (err, data) ->
            console.log 'fs.readFile callback fired'

root = exports ? window
root.Foobar = Foobar

And the following test file for Mocha:

chai = require 'chai'
expect = chai.expect
chai.should()

{Foobar} = require '../source/foobar'

describe 'Foobar', ->
    foobar = null
    it 'does nothing', ->
        foobar = new Foobar
        foobar.test 'foobar.txt'

I run the test:

mocha --compilers coffee:coffee-script -R spec

Strangely for me console logs nothing. When I change my Coffee to this (added two lines at the end):

class Foobar
    test: (path) ->
        fs = require 'fs'
        fs.readFile path, (err, data) ->
            console.log 'fs.readFile callback fired'

root = exports ? window
root.Foobar = Foobar

foobar = new Foobar
foobar.test 'foobar.txt'

I run the test, and now console logs fs.readFile callback fired twice, as expected.

So, why console was empty in the first case?

  • 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-09T13:14:23+00:00Added an answer on June 9, 2026 at 1:14 pm

    It’s possible that your tests are ending before the readFile callback is executed. The test method should accept a callback:

    class Foobar
        test: (path, callback) ->
            fs.readFile path, (err, data) ->
                console.log 'fs.readFile callback fired'
                callback err, data
    

    That way you can write your test to run asynchronously:

    it 'calls callback', (done) ->
        foobar = new Foobar()
        foobar.test 'foobar.txt', done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following three .NET types: I have an interface, an abstract class,
Please consider the following scenario. I have a form with a property: class MyForm
So, please consider the following situation I have a super class of type Shapes
please consider following code #include <iostream> using namespace std; class Digit { private: int
Please consider the following: we have a Spring bean B which is advised with
Please Consider this scenario: We have a base class called clsMain : class clsMain
Please consider the following code: mpz_t x, n, out; mpz_init_set_ui(x, 2UL); mpz_init_set_ui(n, 7UL); mpz_init(out);
please consider this code : 1)public static class MyClass 2){ 3) public static DateTime
Please consider the following: http://jsfiddle.net/CASM6/9/ I have two rows of tabs. there are two
please consider the following: I have a queue of objects represented as an array.

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.