caolan / caolan/nodeunit

Testing response from a call back failure.

Aperta
#303 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
1.9k
Fork
359
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con il test stripReady mostrato e con il ciclo di vita dei test asincroni di nodeunit, quindi esegui il test con la configurazione hardware descritta nell’issue. Il lavoro è completato quando l’evento ready viene osservato e la relativa assertion viene completata prima che nodeunit termini, con un comportamento riproducibile o spiegato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.