Skip to content

Commit

Permalink
feat(adapter): log when Jasmine fails because no expect() were run (#238
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dtychshenko authored and johnjbarton committed Sep 10, 2019
1 parent 76f092a commit 646796e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/adapter.js
Expand Up @@ -271,6 +271,12 @@ function KarmaReporter (tc, jasmineEnv) {
}
}

// When failSpecWithNoExpectations is true, Jasmine will report specs without expectations as failed
if (result.executedExpectationsCount === 0 && specResult.status === 'failed') {
result.success = false
result.log.push('Spec has no expectations')
}

tc.result(result)
delete specResult.startTime
}
Expand Down
19 changes: 19 additions & 0 deletions test/adapter.spec.js
Expand Up @@ -137,6 +137,7 @@ describe('jasmine adapter', function () {

it('should report executedExpectCount 0 if no expectations', function () {
karma.result.and.callFake(function (result) {
expect(result.success).toBe(true)
expect(result.executedExpectationsCount).toBe(0)
})

Expand All @@ -158,6 +159,24 @@ describe('jasmine adapter', function () {
expect(karma.result).toHaveBeenCalled()
})

describe('when spec status is failed and no expect() calls ran', function () {
it('should report fail result and log a message', function () {
karma.result.and.callFake(function (result) {
expect(result.success).toBe(false)
expect(result.log.length).toBe(1)
expect(result.executedExpectationsCount).toBe(0)
})

spec.result.status = 'failed'
spec.result.failedExpectations = []
spec.result.passedExpectations = []

reporter.specDone(spec.result)

expect(karma.result).toHaveBeenCalled()
})
})

it('should report errors in afterAll blocks', function () {
spyOn(karma, 'complete')
spyOn(karma, 'error')
Expand Down

0 comments on commit 646796e

Please sign in to comment.