Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter): handle new Jasmine optional behavior for specs without expectations #238

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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