问题描述
我是Salesforce中开玩笑的测试新手。我正在尝试测试是否在单击按钮时将正确的参数传递给了APEX方法,但是出现了错误提示
TypeError: Cannot set property 'id' of null
298 | // Select button for executing Apex call
299 | const buttonEl = element.shadowRoot.querySelector('lightning-button[class="reapply-button slds-m-left_x-small"]');
> 300 | buttonEl.id = USER_INPUT;
| ^
301 | buttonEl.click();
这是我在HTML中的for:each按钮
<lightning-button class="reapply-button slds-m-left_x-small" variant="brand-outline" label="Reapply" onclick={handlereapply} id={current.Id}></lightning-button>
这是我开玩笑的测试课
import getSubcontractWithRecordId from "@salesforce/apex/subcontractApp.getSubcontractWithRecordId";
// Mocking imperative Apex method call
jest.mock(
"@salesforce/apex/subcontractApp.getSubcontractWithRecordId",() => {
return {
default: jest.fn()
};
},{ virtual: true }
);
const APEX_RECORD_BY_ID = [
{
Id: "a1B3I100001JBkrUAG",Start_Date__c: "2020-09-18",End_Date__c: "2020-10-10"
}];
describe("c-subcontract-app-apex-imperative-call-method",() => {
afterEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
jest.clearAllMocks();
});
function flushPromises() {
// eslint-disable-next-line no-undef
return new Promise((resolve) => setImmediate(resolve));
}
it('passes the record id input to the Apex method correctly',() => {
const USER_INPUT = 'a1B3I100001JBkrUAG';
const APEX_PARAMETERS = { record_id: USER_INPUT };
getSubcontractWithRecordId.mockResolvedValue(APEX_RECORD_BY_ID);
// Create initial element
const element = createElement('c-apex-imperative-method-with-params',{
is: SubcontractApp
});
document.body.appendChild(element);
// Select button for executing Apex call
const buttonEl = element.shadowRoot.querySelector('lightning-button[class="reapply-button slds-m-left_x-small"]');
buttonEl.id = USER_INPUT;
buttonEl.click();
return flushPromises().then(() => {
// Validate parameters of mocked Apex call
expect(getSubcontractWithRecordId.mock.calls[0][0]).toEqual(APEX_PARAMETERS);
});
});
});
这是顶点类声明
public static Subcontract__c getSubcontractWithRecordId(String record_id){
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)