caolan / caolan/nodeunit

Testing response from a call back failure.

Open
#303 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.9k
Forks
359
PR merge metrics
No merged PRs in 30d

Description

So I have some code that requires waiting for a call back and testing the response of it.

For some reason the callback never managed to get called. I've stepped through the code with the debugger but the nodeunit process finishes (with unfinished tests) before the callback can actually fire. I have no doubt I am doing something wrong but no idea what.

This is the test code I'm using:

exports["Strip - Firmata"] = {
      setUp: function(done){
          this.board = newBoard();
          done();
      },
      tearDown: function(done) {
          Board.purge();
          restore(this);
          done();
      },

      stripReady: function(test) {
          test.expect(1);

          var strip = new pixel.Strip({
              data: 6,
              length: 8,
              board: this.board,
              controller: "FIRMATA",
          });

          strip.on("ready", function() {
              console.log("strip ready");
              test.ok(true);
              test.done();
          });
      },
  }

For context: The stripReady test needs to test that a particular event is being emitted by the strip object once it's good to go (this is talking to some hardware behind the scenes). Down the line I'll want to test the appropriate error events as well.

When I trace this with the debugger, the strip constructor gets called, the handler gets bound but right at the moment the handler is bound nodeunit then exits.

As such it doesn't get a chance to drop into the ready handler shown above. I can trace to the point where it emits the message on the Strip side but that event handler never gets called.

So the question is how do I get nodeunit to hang around long enough to get the response back?

FYI the strip constructor is correct and it working properly with the hardware.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shown stripReady test and nodeunit's asynchronous test lifecycle, then run the test against the hardware setup described in the issue. Done means the ready event is observed and its assertion completes before nodeunit exits, with the behavior reproducible or explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.