Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda