()
| 158 | |
| 159 | export const jestConsoleContext = |
| 160 | <Ctx extends BaseContext>() => |
| 161 | (c: Ctx) => { |
| 162 | const ctx = c as Ctx & ConsoleContext |
| 163 | |
| 164 | beforeEach(() => { |
| 165 | ctx.mocked['console.error'] = test.spyOn(console, 'error').mockImplementation(() => {}) |
| 166 | ctx.mocked['console.log'] = test.spyOn(console, 'log').mockImplementation(() => {}) |
| 167 | ctx.mocked['console.info'] = test.spyOn(console, 'info').mockImplementation(() => {}) |
| 168 | ctx.mocked['console.warn'] = test.spyOn(console, 'warn').mockImplementation(() => {}) |
| 169 | }) |
| 170 | |
| 171 | afterEach(() => { |
| 172 | ctx.mocked['console.error'].mockRestore() |
| 173 | ctx.mocked['console.log'].mockRestore() |
| 174 | ctx.mocked['console.info'].mockRestore() |
| 175 | ctx.mocked['console.warn'].mockRestore() |
| 176 | }) |
| 177 | |
| 178 | return ctx |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Test context contributor. Mocks process.std(out|err).write with a Jest spy before each test. |
no outgoing calls