I am struggling to grasp the concept of branch coverage, especially when it involves optional chaining in TypeScript.
Below is my code snippet:
type testingType = {
b?: { a?: number };
};
export function example(input: testingType) {
return input.b?.a;
}
And here is the test I wrote, although it's just for passing purposes to generate the report:
test('test', () => {
example({});
expect(1).toBe(1);
});
The screenshot below shows the coverage report with 3 out of 4 branches covered:
I am puzzled as to why there are a total of 4 branches. Shouldn't it be only 2 branches?
b
definedb
undefined.