Can anyone share any example related to edge case testing in javascript and also any example related to function testing in javascript using jest.
const activityFunction: AzureFunction = async function (context: Context): Promise<string> {
try {
let mappingArr = [] as any;
mapCategoryNameToNameOfNetwork(mappingArr, context);
return
} catch (err) {
context.log.error("Error while mapping category name to name of networks", err)
throw err;
}
};
I want to test this function as this is giving blank response. I am not able to test it like i was testing for normal functions. Do anyone have any solution that how i should move ahead with this?
Thanks in advance for help.

Here, a folder for HTTP Trigger1 is created.
npm init -y
npm i jest
It adds the required packages to the project for testing the function with jest.
package.json to replace the existing test command: "scripts": {
"test": "jest"
}
It looks like:

module.exports = {
log: jest.fn()
};
It mocks the log function in default context.
const httpFunction = require('./index');
const context = require('../testing/defaultContext')
test('Http trigger should return known text', async () => {
const request = {
query: { name: 'Bill' }
};
await httpFunction(context, request);
expect(context.log.mock.calls.length).toBe(1);
expect(context.res.body).toEqual('Hello Bill');
});
These are steps and code format of running the JavaScript Azure Function using Jest.
npm testIf the test failed, it shows like below:

And Here the test is failed because in the test script, the result string should be like Hello {name} where as in the boilerplate code of Azure Function Http Trigger, the result string is Hello, {name}. This function executed successfully.
So both doesn't match, the test failed.
Modified the HTTP Trigger Function to output the result string same as test script result i.e., Hello {name}

The test is passed as the function's output is Hello Bill which is same as the Test Script expected output.
Here are the references for the Azure JavaScript Function Testing using Jest and the edge cases testing: