Skip to content

Commit

Permalink
Add tests on colors. #34
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Jun 28, 2015
1 parent 8f90ae2 commit 3626304
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

## Other

* Add tests on colors. [#34](https://github.com/bcaudan/jasmine-spec-reporter/issues/34)
* Bump dependencies versions

# 2.2.3
Expand Down
99 changes: 99 additions & 0 deletions spec/colors-display.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
describe 'with colors', ->
describe 'default', ->
beforeEach ->
@reporter = new SpecReporter(displayPendingSpec: true)

describe 'when spec', ->
it 'should report success', ->
outputs = new Test(@reporter, ->
@describe 'suite', =>
@it 'successful spec', =>
@passed()
, true).outputs
expect(outputs).not.contains ' ✓ successful spec'
expect(outputs).contains ' ' + '✓ successful spec'.green


it 'should report failure', ->
outputs = new Test(@reporter, ->
@describe 'suite', =>
@it 'failed spec', =>
@failed()
, true).outputs
expect(outputs).not.contains ' ✗ failed spec'
expect(outputs).contains ' ' + '✗ failed spec'.red


it 'should not report pending', ->
outputs = new Test(@reporter, ->
@describe 'suite', =>
@xit 'pending spec', =>
, true).outputs
expect(outputs).not.contains ' * pending spec'
expect(outputs).contains ' ' + '* pending spec'.yellow


describe 'custom', ->
beforeEach ->
@reporter = new SpecReporter(displayPendingSpec: true, colors: {
success: 'magenta',
failure: 'white',
pending: 'blue'
})

describe 'when spec', ->
it 'should report success', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@it 'successful spec', =>
@passed()
, true).outputs)
.contains ' ' + '✓ successful spec'.magenta


it 'should report failure', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@it 'failed spec', =>
@failed()
, true).outputs)
.contains ' ' + '✗ failed spec'.white


it 'should not report pending', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@xit 'pending spec', =>
, true).outputs)
.contains ' ' + '* pending spec'.blue


describe 'disabled', ->
beforeEach ->
@reporter = new SpecReporter(displayPendingSpec: true, colors: false)

describe 'when spec', ->
it 'should report success', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@it 'successful spec', =>
@passed()
, true).outputs)
.contains ' ✓ successful spec'


it 'should report failure', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@it 'failed spec', =>
@failed()
, true).outputs)
.contains ' ✗ failed spec'


it 'should not report pending', ->
expect(new Test(@reporter, ->
@describe 'suite', =>
@xit 'pending spec', =>
, true).outputs)
.contains ' * pending spec'
9 changes: 5 additions & 4 deletions spec/helpers/test-helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ addMatchers = ->
pass: false

class Test
constructor: (@reporter, @testFn) ->
@init()
constructor: (@reporter, @testFn, withColor = false) ->
@init(withColor)
@run()

init: ->
init: (withColor) ->
@outputs = []
@summary = []
logInSummary = false
console.log = (stuff) =>
stuff = stuff.stripColors.stripTime
unless withColor
stuff = stuff.stripColors.stripTime
logInSummary = true if /^(Executed|\*\*\*\*\*\*\*)/.test stuff

unless logInSummary
Expand Down

0 comments on commit 3626304

Please sign in to comment.