Skip to content

Commit

Permalink
feat(adapter): handle new Jasmine behavior for specs without expectat…
Browse files Browse the repository at this point in the history
…ions

If Jasmine is configured with failSpecWithNoExpectations set to true, it will report specs without expectations as failures. This updates the adapter to handle such case.
  • Loading branch information
dtychshenko committed Sep 7, 2019
1 parent 76f092a commit b57a7af
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 there are no expecations run', 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 b57a7af

Please sign in to comment.