Skip to content

Commit

Permalink
test: unit testing infrastrutcure/boxen
Browse files Browse the repository at this point in the history
* Includes test for greenboxing

* Better name for test

* Move test next to the code tested

* test(infrastructure/boxen): replace snapshot testing

* test(infrastructure/boxen): using mock aproach to test

* test(infrastructure/boxen): should add margin if config is passed
  • Loading branch information
thiagoarrais authored and victorperin committed Oct 19, 2019
1 parent cf72dc5 commit ffba231
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
collectCoverageFrom: ['<rootDir>/src/**/*.js'],
coverageDirectory: 'coverage',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/**/*.test.js'],
testMatch: ['<rootDir>/tests/**/*.test.js', '<rootDir>/src/**/*.test.js'],
verbose: true,
}
34 changes: 34 additions & 0 deletions src/infrastructure/boxen.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const boxen = require('boxen')
const { greenBox } = require('./boxen')

jest.mock('boxen')
beforeEach(boxen.mockReset)

test('Should call boxen with basic settings and return boxen content', async () => {
boxen.mockReturnValue('MOCKED VALUE')

const input = 'sample input'
const greenBoxConfig = {
padding: 1,
borderStyle: 'double',
borderColor: 'green',
}

const result = greenBox(input)

const boxenMockFirstCall = boxen.mock.calls[0]

expect(boxenMockFirstCall[0]).toEqual(input)
expect(boxenMockFirstCall[1]).toMatchObject(greenBoxConfig)

expect(result).toEqual('MOCKED VALUE')
})

test('Should add margin if config is passed', () => {
boxen.mockReturnValue('MOCKED VALUE')

greenBox('some input', { margin: 4 })

const boxenMockFirstCall = boxen.mock.calls[0]
expect(boxenMockFirstCall[1]).toMatchObject({ margin: 4 })
})

0 comments on commit ffba231

Please sign in to comment.