When a query from salesforce comes back as an empty array, we catch that inside of .then() and throw error which I can console.log and see inside of .catch(). However I am having a hard time testing that error message.
I've tried chai-as-promise and to.eventually.equal('some string'), but came back as AssertionError: expected undefined to equal 'No campaigns for current period.'
cosnt campaignMember = {
getCampaignMembers: async () => {
await login();
return conn.sobject('CampaignMember')
.select('*')
.then((result) => {
if (!result[0]) {
throw Error('No campaigns for current period.');
}
return result;
})
.catch((err) => {
log.error(`Could not get paid current campaigns ${err}`);
});
},
}
module.exports = campaignMember
TEST
it('should pass', async () => {
await otherAsyncMethod();
await expect(campaignMember.getCampaignMembers(currentParent)).to.eventually.equal('No campaigns for current period.');
});
I want to be able to test the error message itself.