Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions integration_tests/__tests__/jasmine_async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ describe('async jasmine', () => {
expect(json.numPendingTests).toBe(1);
expect(json.testResults[0].message).toMatch(/concurrent test fails/);
});

it('async test fails', () => {
const result = runJest.json('jasmine_async', ['async_test_fails.test.js']);

expect(result.status).toBe(1);
expect(result.json.testResults[0].message).toEqual(
expect.stringContaining('Expected value to be truthy, instead received'),
);
});
});
17 changes: 17 additions & 0 deletions integration_tests/jasmine_async/__tests__/async_test_fails.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
*
* @jest-environment jsdom
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now there is no way to assert what testEnvironment a test is run in. But I doubt someone will change this anyways, so shouldn't be a problem

*/

'use strict';

it('async test fails', done => {
setTimeout(() => {
expect(false).toBeTruthy();
done();
}, 1 * 1000);
});
12 changes: 12 additions & 0 deletions packages/jest-environment-jsdom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class JSDOMEnvironment {
document: ?Object;
fakeTimers: ?FakeTimers<number>;
global: ?Global;
errorEventListener: ?Function;
moduleMocker: ?ModuleMocker;

constructor(config: ProjectConfig): void {
Expand All @@ -43,6 +44,13 @@ class JSDOMEnvironment {
};
}

this.errorEventListener = event => {
if (event.error) {
process.emit('uncaughtException', event.error);
}
};
global.addEventListener('error', this.errorEventListener);

this.moduleMocker = new mock.ModuleMocker(global);

const timerConfig = {
Expand All @@ -63,8 +71,12 @@ class JSDOMEnvironment {
this.fakeTimers.dispose();
}
if (this.global) {
if (this.errorEventListener) {
this.global.removeEventListener('error', this.errorEventListener);
}
this.global.close();
}
this.errorEventListener = null;
this.global = null;
this.document = null;
this.fakeTimers = null;
Expand Down