Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

tests: throw in case we encounter unhandled promise rejection #132

Merged
merged 2 commits into from
Dec 20, 2018
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
12 changes: 12 additions & 0 deletions tests/config/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
beforeEach( () => {
expect.hasAssertions();
} );

// Break on unhandled promise rejection (default warning might be overlooked)
// https://github.com/facebook/jest/issues/3251#issuecomment-299183885
// However...
// https://stackoverflow.com/questions/51957531/jest-how-to-throw-an-error-inside-a-unhandledrejection-handler
if ( typeof process.env.LISTENING_TO_UNHANDLED_REJECTION === 'undefined' ) {
process.on( 'unhandledRejection', ( unhandledRejectionWarning ) => {
throw unhandledRejectionWarning; // see stack trace for test at fault
} );
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLED_REJECTION = 'yes';
}
6 changes: 5 additions & 1 deletion tests/unit/client/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ function mockMwEnv( language: string, entityId: any, namespaces: any = null, tit
}
} },
hook: () => new ImmediatelyInvokingEntityLoadedHookHandler( {} ),
Title: title || jest.fn().mockImplementation(),
Title: title || jest.fn().mockImplementation( () => {
return {
getUrl: jest.fn(),
};
} ),
};
}

Expand Down