Skip to content

Instantly share code, notes, and snippets.

@Farenheith
Created February 20, 2020 02:01
Show Gist options
  • Save Farenheith/b3abf2c18bec2c39d9110f000886ed1c to your computer and use it in GitHub Desktop.
Save Farenheith/b3abf2c18bec2c39d9110f000886ed1c to your computer and use it in GitHub Desktop.
Example of test of a code without functions
import { stub } from 'sinon';
import { expect } from 'chai';
describe('runnable.ts', () => {
let target = '../src/runnable.ts';
beforeEach(() => {
stub(console, 'log');
});
afterEach(() => {
delete require.cache[require.resolve(target)];
delete process.env.IS_GOODBYE;
});
it('should log hello world if IS_GOODBYE is not "true"', () => {
process.env.IS_GOODBYE = 'anything else';
require(target);
expect(console.log).to.have.been.calledOnceWithExactly('hello world');
});
it('should log goodbye world if IS_GOODBYE is "true"', () => {
process.env.IS_GOODBYE = 'true';
require(target);
expect(console.log).to.have.been.calledOnceWithExactly('goodbye world!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment