Skip to content

Instantly share code, notes, and snippets.

@Farenheith
Last active February 22, 2020 15:49
Show Gist options
  • Save Farenheith/94f7b9672cb91d9931f1134a2f34f244 to your computer and use it in GitHub Desktop.
Save Farenheith/94f7b9672cb91d9931f1134a2f34f244 to your computer and use it in GitHub Desktop.
Simple test for example-stream.ts
import { expect } from 'chai';
import { stub } from 'sinon';
import * as zlib from 'zlib';
import { streamExample } from '../src/stream-example';
describe.only('streamExample()', () => {
beforeEach(() => {
stub(zlib, 'createGzip').returns('createGZip result' as any);
});
it('should pipe the given stream to a gzip writer', async () => {
const stream = {
pipe: stub().returns('piped stream' as any),
};
const result = streamExample(stream as any);
expect(zlib.createGzip).to.have.been.calledOnceWithExactly();
expect(stream.pipe).to.have.been.calledOnceWithExactly('createGZip result');
expect(result).to.be.eq('piped stream');
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment