From 646796e4fabe7e271c188444171a886d4b28943a Mon Sep 17 00:00:00 2001 From: Dmitriy Tychshenko Date: Tue, 10 Sep 2019 11:36:52 -0400 Subject: [PATCH] feat(adapter): log when Jasmine fails because no expect() were run (#238) --- 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..c27dc71 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 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')