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

Config empty for test wire adapter #70

Open
jjbennett opened this issue Feb 14, 2023 · 3 comments
Open

Config empty for test wire adapter #70

jjbennett opened this issue Feb 14, 2023 · 3 comments

Comments

@jjbennett
Copy link

I was attempting to emit getRelatedListRecords with 2 different sets of data and using the config as mentioned in #15 but the config is always an empty object. There are other reports of the config being blank on stack exchange.

@jmsjtu
Copy link
Member

jmsjtu commented Feb 23, 2023

@jjbennett do you have a repro we can look at?

@jjbennett
Copy link
Author

I created a simple repo and in doing so I found the issue to be when using a dynamic and reactive property in the config. If I hard code the Ids on line 15 and 18 then it works as expected.

config is available if you change line 15 and 18 to...

@wire(getRecord, { recordId: '0017i00001MIvJOAA1', fields: [ID] })
@wire(getRecord, { recordId: '0017i00001MIvKdAAL', fields: [ID] })
import { LightningElement, api, wire } from "lwc";
import { getRecord } from "lightning/uiRecordApi";
import ID from "@salesforce/schema/Account.Id";

export default class ConfigIssue extends LightningElement {
    @api firstRecordId = "0017i00001MIvJOAA1";
    @api secondRecordId = "0017i00001MIvKdAAL";

    @wire(getRecord, { recordId: '$firstRecordId', fields: [ID] })
    firstRecord;

    @wire(getRecord, { recordId: '$secondRecordId', fields: [ID] })
    secondRecord;

    @api getFirstRecordId() {
        return this.firstRecord?.data?.Id;
    }

    @api getSecondRecordId() {
        return this.secondRecord?.data?.Id;
    }
}
import { createElement } from "lwc";
import configIssue from "../configIssue";
import { getRecord } from "lightning/uiRecordApi";

describe("c-config-issue", () => {
    const mockGetRecordFirst = { "Id": "0017i00001MIvJOAA1" };
    const mockGetRecordSecond = { "Id": "0017i00001MIvKdAAL" };

    afterEach(() => {
        while (document.body.firstChild) {
            document.body.removeChild(document.body.firstChild);
        }
        jest.clearAllMocks();
    });

    test("input => result", () => {
        const element = createElement("c-config-issue", {
            is: configIssue
        });
        document.body.appendChild(element);

        getRecord.emit(mockGetRecordFirst, (config) => {
            console.log('config: ', config);
            return config.recordId === "0017i00001MIvJOAA1"
        });
        getRecord.emit(mockGetRecordSecond, (config) => config.recordId === "0017i00001MIvKdAAL");

        expect(element.getFirstRecordId()).toBe("0017i00001MIvJOAA1");
        expect(element.getSecondRecordId()).toBe("0017i00001MIvKdAAL");
    });
});

@jmsjtu
Copy link
Member

jmsjtu commented Apr 6, 2023

@jjbennett sorry I wasn't able to get to this earlier, could you try your test again but wait for a few ticks on the microtask queue?

Something like this:

describe("c-config-issue", () => {
    const mockGetRecordFirst = { "Id": "0017i00001MIvJOAA1" };
    const mockGetRecordSecond = { "Id": "0017i00001MIvKdAAL" };

    afterEach(() => {
        while (document.body.firstChild) {
            document.body.removeChild(document.body.firstChild);
        }
        jest.clearAllMocks();
    });

    test("input => result", () => {
        const element = createElement("c-config-issue", {
            is: Config
        });
        document.body.appendChild(element);

        return Promise.resolve().then(() => {
            ldsAdapterMock.emit(mockGetRecordFirst, (config) => {
                console.log('config: ', config);
                return config.recordId === "0017i00001MIvJOAA1"
            });
            ldsAdapterMock.emit(mockGetRecordSecond, (config) => config.recordId === "0017i00001MIvKdAAL");

            expect(element.getFirstRecordId()).toBe("0017i00001MIvJOAA1");
            expect(element.getSecondRecordId()).toBe("0017i00001MIvKdAAL");
        });
    });
});

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