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 { MyClass } from './my-class'; | |
export function getInstance() { | |
return new MyClass(123); | |
} |
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 * as classToMock from '../src/my-class'; | |
import { getInstance } from '../src/get-instance'; | |
import { stub } from 'sinon'; | |
describe('getInstance()', () => { | |
const mockedInstance = { | |
info: 'MyClass instance', | |
}; | |
beforeEach(() => { |
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 { otherFunction } from './other-function'; | |
export function myFunction() { | |
return otherFunction(123); | |
} |
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 * as functionToMock from '../src/other-function'; | |
import { myFunction } from '../src/my-function'; | |
import { stub } from 'sinon'; | |
describe('myFunction()', () => { | |
beforeEach(() => { | |
stub(functionToMock, 'otherFunction').returns('expected result' as any); | |
}); | |
it('should return otherFunction result', () => { |
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
if (process.env.IS_GOODBYE === 'true') { | |
console.log('goodbye world!'); | |
} else { | |
console.log('hello world'); | |
} |
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'); | |
}); |
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 untestableOldFunction = require('untestable-old-function'); | |
export function doSomethingUntestable() { | |
return untestableOldFunction(123); | |
} |
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 untestableOldFunction = require('untestable-old-function'); | |
export const nowTestableOldFunction = untestableOldFunction as (p: number) => string; |
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 { expect } from 'chai'; | |
import * as wrapper from '../src/untestable-wrapper'; | |
import untestableOldFunction = require('untestable-old-function'); | |
describe('untestable-wrapper', () => { | |
it('should export untestableOldFunction as nowTestableOldFunction', () => { | |
expect(wrapper.nowTestableOldFunction).to.be.eq(untestableOldFunction); | |
}); | |
}); |
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 { nowTestableOldFunction } from './untestable-wrapper'; | |
export function doSomethingUntestable() { | |
return nowTestableOldFunction(123); | |
} |