forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8692bc
commit 3affc08
Showing
3 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
framework/default/ortoo-core/default/lwc/errorRenderer/__tests__/errorRenderer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import displayError from 'c/errorRenderer'; | ||
|
||
let showToastEvent = function ShowToastEvent( details ) { | ||
this.detail = details | ||
}; | ||
|
||
jest.mock('lightning/platformShowToastEvent', () => ({ | ||
ShowToastEvent: showToastEvent | ||
})); | ||
|
||
describe('c-error-renderer', () => { | ||
afterEach(() => { | ||
}); | ||
|
||
it( 'When the passed error is a string, will raise a toast with the message as the given text', () => { | ||
|
||
console.error = jest.fn(); | ||
|
||
let objectToRunAgainst = { | ||
dispatchEvent: jest.fn() | ||
}; | ||
|
||
let error = 'An error string'; | ||
|
||
displayError.call( objectToRunAgainst, error ); | ||
|
||
expect( objectToRunAgainst.dispatchEvent ).toBeCalled(); | ||
|
||
let dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0]; | ||
|
||
expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' ); | ||
expect( dispatchedEvent.detail.message ).toBe( error ); | ||
expect( dispatchedEvent.detail.variant ).toBe( 'error' ); | ||
|
||
expect( console.error ).toHaveBeenCalledTimes( 1 ); | ||
let reportedError = console.error.mock.calls[0][0]; | ||
|
||
expect( reportedError ).toBe( error ); | ||
}); | ||
|
||
it( 'When the passed error is an Apex exception object, will raise a toast with the message as the given text', () => { | ||
|
||
console.error = jest.fn(); | ||
|
||
let objectToRunAgainst = { | ||
dispatchEvent: jest.fn() | ||
}; | ||
|
||
let error = { | ||
body: { | ||
message: 'An error message in the body' | ||
} | ||
} | ||
|
||
displayError.call( objectToRunAgainst, error ); | ||
|
||
expect( objectToRunAgainst.dispatchEvent ).toBeCalled(); | ||
|
||
let dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0]; | ||
|
||
expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' ); | ||
expect( dispatchedEvent.detail.message ).toBe( 'An error message in the body' ); | ||
expect( dispatchedEvent.detail.variant ).toBe( 'error' ); | ||
|
||
expect( console.error ).toHaveBeenCalledTimes( 1 ); | ||
let reportedError = console.error.mock.calls[0][0]; | ||
|
||
expect( reportedError ).toBe( error ); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters