forked from trailheadapps/lwc-recipes
-
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.
Adding Jest tests for @wire (trailheadapps#62)
- Loading branch information
1 parent
8fbd996
commit 23a8de9
Showing
19 changed files
with
4,469 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
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
7 changes: 7 additions & 0 deletions
7
force-app/main/default/lwc/wireCurrentPageReference/__tests__/data/CurrentPageReference.json
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,7 @@ | ||
{ | ||
"type": "standard__navItemPage", | ||
"attributes": { | ||
"apiName": "Wire" | ||
}, | ||
"state": {} | ||
} |
39 changes: 39 additions & 0 deletions
39
...-app/main/default/lwc/wireCurrentPageReference/__tests__/wireCurrentPageReference.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,39 @@ | ||
import { createElement } from 'lwc'; | ||
import WireCurrentPageReference from 'c/wireCurrentPageReference'; | ||
import { CurrentPageReference } from 'lightning/navigation'; | ||
import { registerTestWireAdapter } from '@salesforce/lwc-jest'; | ||
|
||
const mockCurrentPageReference = require('./data/CurrentPageReference.json'); | ||
|
||
// Register as an standard test wire adapter. Some tests verify the provisioned values trigger desired behavior. | ||
const currentPageReferenceAdapter = registerTestWireAdapter( | ||
CurrentPageReference | ||
); | ||
|
||
describe('c-wire-current-page-reference', () => { | ||
afterEach(() => { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
it('renders the current page reference as <pre> tag', () => { | ||
// Create element | ||
const element = createElement('c-wire-current-page-reference', { | ||
is: WireCurrentPageReference | ||
}); | ||
document.body.appendChild(element); | ||
|
||
const preEl = element.shadowRoot.querySelector('pre'); | ||
expect(preEl).not.toBeNull(); | ||
|
||
currentPageReferenceAdapter.emit(mockCurrentPageReference); | ||
|
||
return Promise.resolve().then(() => { | ||
expect(preEl.textContent).toBe( | ||
JSON.stringify(mockCurrentPageReference, null, 2) | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.