I am trying to write Jest test for a component with two @wired
calls (both bound to functions), but I get assertion error about property of second @wire
call not being annotated with wire annotation.
Error: Assert Violation: @wire on "handlePicklistResult": dot-notation reactive parameter "accountObjectInfo.defaultRecordTypeId" must refer to a @wire property
Any suggestions?
Here is sample code that I am trying to test:
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues, getObjectInfo } from 'lightning/uiObjectInfoApi';
import TYPE_FIELD from '@salesforce/schema/Account.Type';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
export default class Democomponent extends LightningElement {
@track accountObjectInfo;
@track error;
@track picklistValues;
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
handleResult({error, data}) {
if(data) {
this.accountObjectInfo = data;
} else {
this.error = error;
}
}
@wire(getPicklistValues, {recordTypeId: "$accountObjectInfo.defaultRecordTypeId", fieldApiName: TYPE_FIELD})
handlePicklistResult({error, data}) {
if(data) {
this.picklistValues = data.values;
} else {
this.error = error;
}
}
}
Simple test I want to perform:
import {registerLdsTestWireAdapter} from '@salesforce/sfdx-lwc-jest';
import {createElement} from 'lwc';
import {getObjectInfo, getPicklistValues} from 'lightning/uiObjectInfoApi';
import TestPage from 'c/testPage';
const mockGetObjectInfo = require('./data/getObjectInfo.json');
const mockGetPicklistValues = require('./data/getPicklistValues.json');
const getObjectInfoAdapter = registerLdsTestWireAdapter(getObjectInfo);
const getPicklistValuesAdapter = registerLdsTestWireAdapter(getPicklistValues);
describe('c-test-page', () => {
it('Should display test page', () => {
const element = createElement('c-test-page', {
is: TestPage
});
document.body.appendChild(element);
getObjectInfoAdapter.emit(mockGetObjectInfo);
getPicklistValuesAdapter.emit(mockGetPicklistValues);
const picklistItems = element.shadowRoot.querySelectorAll('div.picklistItem');
expect(picklistItems.length).toEqual(5);
});
});