Open vdyn opened 1 year ago
I copy/pasted the code and ran the test and both pass for me:
PASS force-app/main/default/lwc/customComponent/__tests__/customComponent.test.js
custom component test
√ connectedCallback (143 ms)
√ customMethod (15 ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 3.918 s
Ran all test suites matching /force-app\\main\\default\\lwc\\customComponent\\/i.
Using:
Can you consolidate the Apex into a single call? It seems strange to make two calls to Apex in a connectedCallback
instead of a single call that would return the data both calls would make, since each call is a separate trip to the server and it would be more efficient to bundle the needed data in a single call.
For example, if you have:
@AuraEnabled
public static Map<String, String> getResult01() {
return new Map<String, String>{
'field0101' => 'a',
'field0102' => 'b'
};
}
@AuraEnabled
public static Map<String, String> getResult02() {
return new Map<String, String>{
'field0201' => 'c',
'field0202' => 'd'
};
}
Then you could do something like:
public static Map<String, String> getResult01() {
return new Map<String, String>{
'field0101' => 'a',
'field0102' => 'b'
};
}
public static Map<String, String> getResult02() {
return new Map<String, String>{
'field0201' => 'c',
'field0202' => 'd'
};
}
@AuraEnabled
public static Map<String, Map<String, String>> getResults() {
return new Map<String, Map<String, String>>{
'result01' => getResult01(),
'result02' => getResult02()
};
}
And in the initialization
:
async initialization() {
const results = await getResults();
this.value01 = results.result01.field0101;
this.value02 = results.result02.field0201;
}
@vdyn Could you provide a GitHub repo with the necessary code and steps to reproduce the issue?
Description
connectedCallback method does not complete calls to mock modules before tests start.
Steps to Reproduce
customComponent.js
customComponent.test.js
Expected Results
First tests work as expected. Please note that the second test is for check the correct code flow.
Actual Results
First test fails. The first value (the result to call getResult01) is correct, but the second value (the result to call getResult02) is undefined.
Version
Possible Solution
No solution found.
Additional context/Screenshots