floatdrop / stream-assert

Assertion library for streams
18 stars 4 forks source link

chained stream assert #2

Closed huang-xiao-jian closed 10 years ago

huang-xiao-jian commented 10 years ago

Hi: It seems that, there is several bugs on chained stream assertion. Shared code

var array = require('stream-array');
var assert = require('stream-assert');
var should = require('should');

When test like this, timeout error happened

describe('chain assertion test', function() {
    it('chain assertion', function(done) {
        array([1, 2, 3])
            .pipe(assert.first(function(data) { data.should.eql(1);}))
            .pipe(assert.second(function(data) { data.should.eql(2);}))
            .pipe(assert.nth(2, function(data) { data.should.eql(3); }))
            .on('end', done)            
    })
})          

When test like below, test case success, It seems that nth method doesn't support chained assertion.

describe('chain assertion test', function() {
    it('chain assertion', function(done) {
        array([1, 2, 3])
            .pipe(assert.first(function(data) { data.should.eql(1);}))
            .pipe(assert.second(function(data) { data.should.eql(2);}))
            .on('end', done)    
            .pipe(assert.nth(2, function(data) { data.should.eql(3); }))        
    })
})          

Also, in below case, It still success, which should fail.

describe('chain assertion test', function() {
    it('chain assertion', function(done) {
        array([1, 2, 3])
            .pipe(assert.first(function(data) { data.should.eql(1);}))
            .pipe(assert.second(function(data) { data.should.eql(100);}))
            .on('end', done)    
            .pipe(assert.nth(2, function(data) { data.should.eql(3); }))

    })
})
floatdrop commented 10 years ago

API have changed in 2.0.0, now you should use assert.end instead of on('end').

In last example you should replace on('end', done) to on('assertion', done).