Here’s a potential JSSpec spec for Sequentially.trickle.map:
[code language=”javascript”]
describe(‘Sequentially.trickle.map’, {
‘should apply to all the elements’: function() {
Sequentially.trickle.map(
[‘a’, ‘b’, ‘c’],
function(x) { return x + 1 },
1,
function(result) {
value_of(result.join(’,’)).should_be(‘a1,b1,c1’);
});
});
}
});
[/code]
This doesn’t work. The problem is that Sequentially.trickle.map is asynchronous (it defers most of its computation – including the invocation of the callback – via setTimeout). This means that should_be isn’t called until after the spec has returned. If it succeeds, this isn’t a problem, but if it fails, JSSpec can’t associate it with the failing spec – worse, JSSpec will have already have marked it successful.
Read the rest of this entry »