You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
sfdx-lwc-jest: 1.4.1
Node: 18.9.0
Windows 10
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()
};
}
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
The text was updated successfully, but these errors were encountered: