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

Commit

Permalink
(#443) testing: log eventBusMock subscriber errors by default
Browse files Browse the repository at this point in the history
  • Loading branch information
x1B committed Apr 7, 2017
1 parent 6cec9cf commit 9b046dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

## Last Changes

- [#443](https://github.com/LaxarJS/laxar/issues/443): testing: initialize eventBusMock with noisy error log
- [#448](https://github.com/LaxarJS/laxar/issues/448): documentation: fixed markdown indent in API index


Expand Down
6 changes: 5 additions & 1 deletion lib/testing/event_bus_mock.js
Expand Up @@ -57,7 +57,11 @@ export function create( { nextTick, errorHandler } = {} ) {
createLogMock(),
nextTick || fallbackTick,
setTimeout,
errorHandler
errorHandler || (( ...args ) => {
if( window.console && window.console.error ) {
window.console.error( ...args );
}
})
);

/**
Expand Down
17 changes: 17 additions & 0 deletions lib/testing/spec/event_bus_mock_spec.js
Expand Up @@ -65,6 +65,23 @@ describe( 'An eventBus mock', () => {

///////////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'reports subscriber errors to console.error by default', () => {
spyOn( window.console, 'error' );
eventBusMock = createEventBusMock();
let e;
eventBusMock.subscribe( 'myEvent', () => {
e = new Error( 'error' );
throw e;
} );
eventBusMock.publish( 'myEvent' );
eventBusMock.flush();

expect( window.console.error ).toHaveBeenCalledWith( jasmine.any( String ), jasmine.any( Object ) );
expect( window.console.error.calls.mostRecent().args[ 1 ][ 'Exception' ] ).toEqual( e );
} );

///////////////////////////////////////////////////////////////////////////////////////////////////////////

it( 'allows to synchronously flush pending events', () => {
const spyA = jasmine.createSpy( 'A' );
const spyB = jasmine.createSpy( 'B' );
Expand Down

0 comments on commit 9b046dd

Please sign in to comment.