2

Currently I am mocking the jsforce connection call via jest.spyOn I m able to mock for login method of jsforce.Connection but not able to mock sobject of jsforce.Connection. If I mock that too it show me some of lines are uncovered in that method where I am logging the errors and responses via check

here is the example like I m doing -

    const userInfo: UserInfo = { id: '0001', organizationId: '0001200', url: 'https://test.salesforce.com/id/0001/001200' };
    const successResult: RecordResult[] = [{ id: 'A0001', success: true }];
    const sObject: any = { upsert: () => { return Promise.resolve(successResult) } };
    jest.spyOn(salesforceAuthService, 'searchAccount').mockReturnValue(Promise.resolve('A0001'));
    jest.spyOn(jsforce.Connection.prototype, 'login').mockReturnValue(Promise.resolve(userInfo));
    jest.spyOn(jsforce.Connection.prototype, 'sobject').mockImplementation().mockReturnValue(sObject);

Also If I give the type to sObject of SObject then it gives me an error(highlighting the upsert) that it can't assign the Type RecordResult[] to RecordResult. And if I do the alternate it gives issue that can't assign RecordResult to RecordResult[]

skyboyer
  • 22,209
  • 7
  • 57
  • 64
RJ grover
  • 91
  • 1
  • 5

0 Answers0