Skip to content

Commit

Permalink
Adding Jest tests for @wire (trailheadapps#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
muenzpraeger authored Mar 1, 2019
1 parent 8fbd996 commit 23a8de9
Show file tree
Hide file tree
Showing 19 changed files with 4,469 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement } from 'lwc';
import ApexImperativeMethod from 'c/apexImperativeMethod';
import getContactList from '@salesforce/apex/ContactController.getContactList';

// Mocking impertive Apex method call
// Mocking imperative Apex method call
jest.mock(
'@salesforce/apex/ContactController.getContactList',
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement } from 'lwc';
import ApexImperativeMethodWithParams from 'c/apexImperativeMethodWithParams';
import findContacts from '@salesforce/apex/ContactController.findContacts';

// Mocking impertive Apex method call
// Mocking imperative Apex method call
jest.mock(
'@salesforce/apex/ContactController.findContacts',
() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "standard__navItemPage",
"attributes": {
"apiName": "Wire"
},
"state": {}
}
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)
);
});
});
});
Loading

0 comments on commit 23a8de9

Please sign in to comment.