Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Testing response from a call back failure.

未關閉
#303 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
javascript
領域
testing-qa

研究方向

先從所示的 stripReady 測試和 nodeunit 的非同步測試生命週期開始,然後使用 issue 中描述的硬體設定執行測試。當觀察到 ready 事件且其 assertion 在 nodeunit 結束前完成,並且該行為可重現或已獲得解釋時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
JavaScript
星號
1.9k
分支
359
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

caolan/nodeunit 的其他 Issue

查看 caolan/nodeunit 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。