I am a relative newbie to all things javascript, node.js, mocha etc.
In my code I have a Unit object that has a disable()
that sets the disabled property to true and a isDisabled()
that returns the disabled property. It also has a method nextTurnReset()
that resets the unit on the start of the next turn. I have written a test suite to test this behavior. I first disable the object and then try to test to see if it is disabled. However, the unit variable inside my first test - which is within the anonymous function passed to the Mocha's it()
method - is in the the non-disabled state as I observed with node's debugger.
describe('#disable()', function() {
var unit = tests.newUnit();
unit.disable();
debugger;
it('disabled off turn?', function() {
debugger;
(unit.isDisabled()).should.be.exactly(true);
});
unit.nextTurnReset();
it('disabled on next turn?', function() {
(unit.isDisabled()).should.be.exactly(true);
});
unit.nextTurnReset();
it('disabled on 2nd turn?', function() {
(unit.isDisabled()).should.be.exactly(false);
});
});
for the record, the first two tests fail, and the last one succeeds indicating the unit is never disabled at all.
from using the node debugger's repl: After the first debugger;
statement, unit.disabled == true
, but after the second debugger;
statement unit.disabled == false
. I expect the value to true in both cases.
Any idea why this would be the case? Also, what is the correct way of writing Mocha tests to get my expected result?
Thanks so much!
Aucun commentaire:
Enregistrer un commentaire