I'm having some trouble understanding branch coverage when it comes to optional chaining with typescript.
Here is my code
type testingType = {
b?: { a?: number };
};
export function example(input: testingType) {
return input.b?.a;
}
Here is the test (just forcing it to pass in order to generate the report)
test('test', () => {
example({});
expect(1).toBe(1);
});
This is the coverage report screenshot (branch coverage 3/4)
I'm trying to wrap my head around why there are 4 branches in total. Shouldn't there be 2 branches instead?
b
definedb
undefined.