I am using mocha/supertest/should.js to test my Rest Service
GET /files/
returns file as stream.
How can I assert in should.js
You have 3 solutions:
First:
Compare the result strings
tmpBuf.toString() === testBuf.toString();
Second:
Using a loop to read the buffers byte by byte
var index = 0,
length = tmpBuf.length,
match = true;
while (index < length) {
if (tmpBuf[index] === testBuf[index]) {
index++;
} else {
match = false;
break;
}
}
match; // true -> contents are the same, false -> otherwise
Third:
Using a third-party module like buffertools and buffertools.compare(buffer, buffer|string) method.