From b9c5df80620ac07c3ed403c533db06b0f62f5b2e Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 16 Apr 2019 10:50:03 +0200 Subject: [PATCH] jest-jasmine2: fix describe return value warning being shown if describe throws (#8335) ## Summary Fixes the describe warning part of #8334 (intentionally not marking this as closing the whole issue) ## Test plan Added e2e test case that fails with master build (the stdout `toBe('')` check). --- CHANGELOG.md | 1 + e2e/__tests__/declarationErrors.test.ts | 8 ++++++++ .../__tests__/describeThrow.test.js | 14 ++++++++++++++ packages/jest-jasmine2/src/jasmine/Env.ts | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 e2e/declaration-errors/__tests__/describeThrow.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index e2c8b00c83df..85b653838824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - `[@jest/runtime, @jest/transform]` Allow custom transforms for JSON dependencies ([#2578](https://github.com/facebook/jest/pull/2578)) - `[jest-core]` Make `detectOpenHandles` imply `runInBand` ([#8283](https://github.com/facebook/jest/pull/8283)) - `[jest-haste-map]` Fix the `mapper` option which was incorrectly ignored ([#8299](https://github.com/facebook/jest/pull/8299)) +- `[jest-jasmine2]` Fix describe return value warning being shown if the describe function throws ([#8335](https://github.com/facebook/jest/pull/8335)) ### Chore & Maintenance diff --git a/e2e/__tests__/declarationErrors.test.ts b/e2e/__tests__/declarationErrors.test.ts index fcd5050cfe6d..55004e6e3c3c 100644 --- a/e2e/__tests__/declarationErrors.test.ts +++ b/e2e/__tests__/declarationErrors.test.ts @@ -29,3 +29,11 @@ it('warns if describe returns something', () => { expect(result.status).toBe(0); expect(normalizeCircusJasmine(result.stdout)).toMatchSnapshot(); }); + +it('errors if describe throws', () => { + const result = runJest('declaration-errors', ['describeThrow.test.js']); + + expect(result.status).toBe(1); + expect(result.stdout).toBe(''); + expect(result.stderr).toContain('whoops'); +}); diff --git a/e2e/declaration-errors/__tests__/describeThrow.test.js b/e2e/declaration-errors/__tests__/describeThrow.test.js new file mode 100644 index 000000000000..d139d73fddaf --- /dev/null +++ b/e2e/declaration-errors/__tests__/describeThrow.test.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +describe('describe throw does not warn', () => { + it('t', () => {}); + throw new Error('whoops'); +}); diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 14d3ea9587ee..494096d9882c 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -416,8 +416,8 @@ export default function(j$: Jasmine) { parentSuite.addChild(suite); currentDeclarationSuite = suite; - let declarationError: null | Error = null; - let describeReturnValue: null | Error = null; + let declarationError: undefined | Error = undefined; + let describeReturnValue: undefined | Error = undefined; try { describeReturnValue = specDefinitions.call(suite); } catch (e) {