Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Any example related to function testing and edge cases in javascript

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.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Create an Azure JavaScript Function in VS Code and test it locally.

enter image description here

Here, a folder for HTTP Trigger1 is created.

  1. Create another folder named as testing under the root of the project in VS Code and run these commands in the terminal of same order:
npm init -y
npm i jest

It adds the required packages to the project for testing the function with jest.

  1. Update the package.json to replace the existing test command:
    "scripts": {
        "test": "jest"
    }

It looks like: enter image description here

  1. In a testing folder, create a file by naming it as defaultContext.js and add this code:
    module.exports = {
        log: jest.fn()
    };

It mocks the log function in default context.

  1. In the Azure Function Folder (i.e., HTTP Trigger1 Folder), add a new file index.test.js by adding this test code:
    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.

  1. To Run the test, use this code in the VS Code Terminal: npm test

If the test failed, it shows like below:

enter image description here

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}

enter image description here

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:

  1. Microsoft Documentation of Azure JavaScript Functions Testing & Debugging.
  2. Edge Cases Testing Code in the Functions
  3. Testing JavaScript with Jest
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda