Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(bar)
jest.unmock('./foo')
jest.mock('./bar')
jest.mock('./bar/foo', () => 'foo')
jest.unmock('./foo/bar')
}
const func2 = () => {
const bar = 'bar'
console.log(bar)
jest.mock('./bar')
jest.unmock('./foo/bar')
jest.mock('./bar/foo', () => 'foo')
jest.unmock('./foo')
}
`
const logger = testing.createLoggerMock()
const createFactory = () => {
return hoist.factory({ logger, compilerModule: tsc } as any)
}
const transpile = (source: string) => tsc.transpileModule(source, { transformers: { before: [createFactory()] } })
describe('hoisting', () => {
it('should have correct signature', () => {
expect(hoist.name).toBe('hoisting-jest-mock')
expect(typeof hoist.version).toBe('number')
expect(hoist.version).toBeGreaterThan(0)
expect(typeof hoist.factory).toBe('function')
})
it('should hoist jest mock() and unmock() statements', () => {
const out = transpile(CODE_WITH_HOISTING)
expect(out.outputText).toMatchInlineSnapshot(`
describe('raiseDiagnostics', () => {
const createTsError = jest.fn(
(list: Diagnostic[]) => new Error(list.map(d => `[TS${d.code}] ${d.messageText}`).join('\n')),
)
const filterDiagnostics = jest.fn(list => list)
const logger = testing.createLoggerMock()
const makeDiagnostic = ({
messageText = 'foo',
code = 9999,
category = DiagnosticCategory.Warning,
}: Partial = {}): Diagnostic => ({ messageText, code, category } as any)
it('should throw when warnOnly is false', () => {
const { raiseDiagnostics } = createConfigSet({ createTsError, filterDiagnostics })
expect(() => raiseDiagnostics([])).not.toThrow()
expect(() => raiseDiagnostics([makeDiagnostic()])).toThrowErrorMatchingInlineSnapshot(`"[TS9999] foo"`)
expect(() => raiseDiagnostics([makeDiagnostic({ category: DiagnosticCategory.Message })])).not.toThrow()
})
it('should not throw when warnOnly is true', () => {
const { raiseDiagnostics } = createConfigSet({
createTsError,
filterDiagnostics,
logger,
import { testing } from 'bs-logger'
import set = require('lodash.set')
import { inspect } from 'util'
import { backportJestConfig } from './backports'
const logger = testing.createLoggerMock()
const logTarget = logger.target
beforeEach(() => {
logTarget.clear()
})
describe('backportJestConfig', () => {
const makeTestsFor = (oldPath: string, _: string, values: any[]) => {
values.forEach(val => {
let original: any
beforeEach(() => {
original = {}
set(original, oldPath, val)
})
describe(`with "${oldPath}" set to ${inspect(val)}`, () => {
it(`should wran the user`, () => {