问题描述:

So I have this app code. Since it is about an asynchronous stream, I don't know how to test something that happens within the stream.

let stream: any = fs.createReadStream(filePath, {start: 12, end: 15});

stream.on('data', function (fourByteStream: any): void {

if ((fourByteStream[0] === 65) && (fourByteStream[1] === 66) &&

(fourByteStream[2] === 67) && (fourByteStream[3] === 68)) { // check the four bytes of the stream

analyzedString.passes = true;

}

});

stream.on('end', () => {

this._replaySubjectSource.next(analyzedString);

});

I just want this test expectation to pass

 spyOn(mySvc._replaySubjectSource, "next");

expect(mySvc._replaySubjectSource.next).toHaveBeenCalled();

Whether I inject the service or make it standalone pure Jasmine (sync or async with "done"), it does not. I also tried a setTimeOut function in the test, but basically nothing in that was ever run.

相关阅读:
Top