Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with registerApexTestWireAdapter fail if test run from Visual Studio Code (Salesforce Extension Pack) #181

Open
C00per opened this issue Nov 11, 2020 · 1 comment

Comments

@C00per
Copy link

C00per commented Nov 11, 2020

Description

I'm testing using registerApexTestWireAdapter @wire adapter.
It runs fine if the test is launched from the Powershell. Also, it runs as expected if I launch it using the "Debug Test" option from VSC (Salesforce Extension Pack) See https://developer.salesforce.com/tools/vscode/en/lwc/testing
But if I use the "Run Test" option then DOM is not refreshed after emit() commands in Promise.resolve().then block and the test is failed.

All other tests without egisterApexTestWireAdapter @wire adapter are running fine from the VSC (Salesforce Extension Pack).

I also noticed that the error reproduced if I run the test from CMD but not from Powershell. When I run the test in Powershell it opens CMD during the execution but this time it works as expected. (Test marked green and the correct json created in C:\Users\bunig\Dev\sfdc\KPIManagement\kpimanagement.sfdx\tools\testresults\lwc)

Steps to Reproduce

  1. Create a test that uses registerApexTestWireAdapter @wire adapter.
        it('renders records when data returned',  () => {
            // Create initial element
            const element = createElement('c-main-kpi-set', {
                is: MainKpiSet
            });            
            document.body.appendChild(element);
            getKPISetListAdapter.emit(mockGetKPISetList);

            return Promise.resolve().then(() => {
                const detailEls = element.shadowRoot.querySelectorAll('lightning-vertical-navigation-item');

                expect(detailEls.length).toBe(mockGetKPISetList.length);
                expect(detailEls[0].label).toBe(mockGetKPISetList[0].Name);
            });             
        });
<!-- HTML for component under test -->
                <lightning-vertical-navigation compact selected-item={selectedKpiSetId} onselect={handleSelectKPISet} data-id="navset">                       
                    <lightning-vertical-navigation-section>
                        <template if:true={KPISet}>
                            <template for:each={KPISet} for:item="row">
                                <lightning-vertical-navigation-item key={row.Id} label={row.Name} name={row.Id} title={row.nekpim__Description__c}></lightning-vertical-navigation-item>
                            </template>
                        </template>
                    </lightning-vertical-navigation-section>
                </lightning-vertical-navigation>  
// JS for component under test
    @wire(getKPISetList,{searchString: '$searchString' }) 
    getResults(result){
        this._getKPISetListRresult = result;
        if(result.data){
            this.KPISet = result.data;
        } else if (result.error) {
            this.errorMsg = result.error;
            this.KPISet = undefined;
            this.KPISetMap = undefined;
        }
    }
  1. Run Test pressing the "Run Test" option.
    image
    OR in CMD using the command below
c:\Users\bunig\Dev\sfdc\KPIManagement\kpimanagement\node_modules\.bin\lwc-jest -- --json --outputFile c:\Users\bunig\Dev\sfdc\KPIManagement\kpimanagement\.sfdx\tools\testresults\lwc\test-result-f5d14634-162e-4d3e-97aa-868e96092071.json --testLocationInResults --runTestsByPath force-app\main\default\lwc\mainKpiSet\__tests__\mainKpiSet.test.js --testNamePattern "renders records when data returned"

Expected Results

The test is passed as it passed if the "Debug Test" option selected or the test run from the Powershell.

Actual Results

image

Version

  • @salesforce/sfdx-lwc-jest: 0.7.1
  • Node: 12.18.0

Possible Solution

Additional context/Screenshots

@trevor-bliss
Copy link
Contributor

trevor-bliss commented Nov 18, 2020

@C00per What is the command line equivalent that the VS Code extension is running for debug mode that passes? Does that command pass when run from CMD?

Also, will you try on a newer version of @salesforce/sfdx-lwc-jest and see if you get the same results?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants