|
1 | 1 | const sinon = require('sinon')
|
2 | 2 | const { logger } = require('./logger')
|
| 3 | +import _ from 'lodash' |
3 | 4 |
|
4 | 5 | describe('logger', () => {
|
| 6 | + let spyLog = sinon.spy(logger, 'log') |
| 7 | + |
| 8 | + afterEach(() => { |
| 9 | + // reset after each unit test |
| 10 | + spyLog.resetHistory() |
| 11 | + }) |
| 12 | + |
5 | 13 | // https://github.com/cypress-io/cypress/issues/17542
|
6 | 14 | it('cy.log() shows all arguments in each line when there are multiple args', () => {
|
7 |
| - const spy = sinon.spy(logger, 'log') |
8 |
| - |
9 | 15 | logger.logFormatted({ args: [1, 2, 3] })
|
10 | 16 |
|
11 |
| - expect(spy).to.have.been.calledWith(`%cArgs:`, 'font-weight: bold') |
12 |
| - expect(spy).to.have.been.calledWith(`%c [0]:`, 'font-weight: bold', 1) |
13 |
| - expect(spy).to.have.been.calledWith(`%c [1]:`, 'font-weight: bold', 2) |
14 |
| - expect(spy).to.have.been.calledWith(`%c [2]:`, 'font-weight: bold', 3) |
| 17 | + expect(spyLog).to.have.been.calledWith(`%cArgs:`, 'font-weight: bold') |
| 18 | + expect(spyLog).to.have.been.calledWith(`%c [0]:`, 'font-weight: bold', 1) |
| 19 | + expect(spyLog).to.have.been.calledWith(`%c [1]:`, 'font-weight: bold', 2) |
| 20 | + expect(spyLog).to.have.been.calledWith(`%c [2]:`, 'font-weight: bold', 3) |
| 21 | + }) |
| 22 | + |
| 23 | + describe('_logValues', () => { |
| 24 | + let spyTrim = sinon.spy(_, 'trim') |
| 25 | + |
| 26 | + afterEach(() => { |
| 27 | + // reset after each unit test |
| 28 | + spyTrim.resetHistory() |
| 29 | + }) |
| 30 | + |
| 31 | + it('should not call trim', () => { |
| 32 | + logger._logValues({}) |
| 33 | + logger._logValues({ test: {} }) |
| 34 | + logger._logValues(null) |
| 35 | + logger._logValues(undefined) |
| 36 | + |
| 37 | + expect(spyTrim.getCalls()).to.have.length(0) |
| 38 | + }) |
| 39 | + |
| 40 | + // The positive unit tests to capture if log has been called are already written in |
| 41 | + // the 'cy.log() shows all arguments in each line when there are multiple args' unit test. |
15 | 42 | })
|
16 | 43 | })
|
0 commit comments