4

Hello I am writing unit test case of my function which is like

const Services = {

   test: async (token) => {

    .. ...

   }

}

I have written unit test of this function, report says test covered all lines of this function but async (token) => { shows in yellow background in report which means uncovered branch.

it("test return 200", async () => {

    nock(url)
        .get('/test')
        .reply(200, response);

    const res = await connector.Services.test(token);

    res.should.have.property('name');
});

Does anyone know what could be the issue ?

N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • Does the uncovered branch still show if you reformat the function definition to this? `async test(token) { /* function body on new line */ }` Also, are you using any kind of compiler, like Babel? If so, it's possible that Babel changes your code structure in a way that it introduces a branch to the function declaration which you do not see in the source but the coverage instrumenter reports an untested branch. – Robert Rossmann Jun 13 '18 at 06:14
  • 1. Technically speaking, `async (token) => { ... }` is not really a branch _per se_. It's a value of an object. However, since this value is "executable" (because its of type `function`) I feel like it's okay to think about it as a branch. 2. Could you show the complete code? E.g. show what does the `Services`' `test` function do exactly; similarly, what `response` object is being passed in the body of `it()`. It's really hard to _guess_ what is happening in runtime without knowing these details. – Igor Soloydenko Jun 14 '18 at 04:34

0 Answers0