From b57a7af67c44a846df497d37a34caf8201ee1148 Mon Sep 17 00:00:00 2001 From: Dmitriy T Date: Thu, 22 Aug 2019 17:10:00 -0400 Subject: [PATCH] feat(adapter): handle new Jasmine behavior for specs without expectations 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. --- src/adapter.js | 6 ++++++ test/adapter.spec.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/adapter.js b/src/adapter.js index 278e7fe..9560753 100644 --- a/src/adapter.js +++ b/src/adapter.js @@ -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 } diff --git a/test/adapter.spec.js b/test/adapter.spec.js index 1d4370e..49f17cd 100644 --- a/test/adapter.spec.js +++ b/test/adapter.spec.js @@ -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) }) @@ -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')