caolan / caolan/nodeunit

Testing response from a call back failure.

Đang mở
#303 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
1.9k
Fork
359
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với bài kiểm tra stripReady được hiển thị và vòng đời kiểm tra bất đồng bộ của nodeunit, sau đó chạy bài kiểm tra trên thiết lập phần cứng được mô tả trong issue. Hoàn tất khi sự kiện ready được quan sát và assertion của nó hoàn thành trước khi nodeunit thoát, đồng thời hành vi có thể tái hiện hoặc được giải thích.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
testing-qa
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.