Created
February 20, 2020 02:01
-
-
Save Farenheith/b3abf2c18bec2c39d9110f000886ed1c to your computer and use it in GitHub Desktop.
Example of test of a code without functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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