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
When using the emit and error functions and version 1.1.0 an error is thrown "getAccountList.error" is not a function and "getAccountList.emit is not a function" This previously worked in v0.13.0, I can switch between versions and see the tests pass and then see them fail with v1.1.0.
import{createElement}from'lwc';importWireApexfrom'c/wireApex';importgetAccountListfrom'@salesforce/apex/AccountController.getAccountList';constmockGetAccountList=require('./data/getAccountList.json');constmockGetAccountListNoRecords=require('./data/getAccountListNoRecords.json');describe('c-wire-apex',()=>{afterEach(()=>{while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}// Prevent data saved on mocks from leaking between testsjest.clearAllMocks();});describe('getAccountsList @wire data',()=>{it('renders six records',()=>{constelement=createElement('c-wire-apex',{is: WireApex});document.body.appendChild(element);getAccountList.emit(mockGetAccountList);returnPromise.resolve().then(()=>{constaccountElements=element.shadowRoot.querySelectorAll('p');expect(accountElements.length).toBe(mockGetAccountList.length);expect(accountElements[0].textContent).toBe(mockGetAccountList[0].Name);});});});describe('getAccountsList @wire error',()=>{it('shows error panel element',()=>{constelement=createElement('c-wire-apex',{is: WireApex});document.body.appendChild(element);getAccountList.error();returnPromise.resolve().then(()=>{consterrorElement=element.shadowRoot.querySelector('p');expect(errorElement).not.toBeNull();expect(errorElement.textContent).toBe('No accounts found.');});});});});
// Jest config overrides (if any)// No Jest config overrides.
# Command to repro
sfdx-lwc-jest
Expected Results
I'm expecting to be able to use emit and error in v1.1.0 like v0.13.0
Actual Results
I get the following errors when running the tests:
TypeError: getAccountList.emit is not a function
TypeError: getAccountList.error is not a function
Version
@salesforce/sfdx-lwc-jest: 1.1.0
Node: 16.13.2
Possible Solution
I was able to use the deprecated registerTestWireAdapter to get the emit function and use that to emit data and error properties in order to get my tests running, but that doesn't seem to be the right solution here.
import{registerTestWireAdapter}from"@salesforce/sfdx-lwc-jest";//DeprecatedconstgetAccountListAdapter=registerTestWireAdapter(getAccountList);describe("workaround",()=>{it("can be used like this in the meantime",()=>{// To mock a successful callgetAccountListAdapter.emit({"data" : [{},{},{}]});// To mock an error callgetAccountListAdapter.emit({"error": {"body": {"message": "Some Mock Error"}}});});});
Additional context/Screenshots
If I'm just misunderstanding the api, please let me know and point me in the direction to whatever has replaced it.
The text was updated successfully, but these errors were encountered:
Description
When using the emit and error functions and version 1.1.0 an error is thrown "getAccountList.error" is not a function and "getAccountList.emit is not a function" This previously worked in v0.13.0, I can switch between versions and see the tests pass and then see them fail with v1.1.0.
The example code is from the Write a jest test for wire service trailhead module
Steps to Reproduce
# Command to repro sfdx-lwc-jest
Expected Results
I'm expecting to be able to use emit and error in v1.1.0 like v0.13.0
Actual Results
I get the following errors when running the tests:
TypeError: getAccountList.emit is not a function
TypeError: getAccountList.error is not a function
Version
Possible Solution
I was able to use the deprecated registerTestWireAdapter to get the emit function and use that to emit data and error properties in order to get my tests running, but that doesn't seem to be the right solution here.
Additional context/Screenshots
If I'm just misunderstanding the api, please let me know and point me in the direction to whatever has replaced it.
The text was updated successfully, but these errors were encountered: