I have a vue function that returns an array of strings
1 selectStyles (): string[] {
2 const baseStyles = ['selected-label', 'px-4']
3 const placeholderStyle = this.internalValue?.length === 0 ? 'text-gray-400' : 'text-black'
4
5 return [...baseStyles, placeholderStyle]
6 },
And I have three jest tests cases testing for
- if
internalValue
has a value and it's therefore its length is !0 - if
internalValue
is an empty array and therefore its length is 0 - if
internalValue
is undefined,undefined === 0
is false and therefore second condition is assigned
And yet codecov says that line 3 is a partial hit?
Any idea why?
I read this great response concerning an if statement in python and the results of that, but I don't think it answers my question.
Here are my test cases:
it('selectStyles', () => {
expect(
Select.computed.selectStyles.call({
internalValue: []
})
).toEqual(['selected-label', 'px-4', 'text-gray-400'])
expect(
Select.computed.selectStyles.call({
internalValue: ['some opt selected']
})
).toEqual(['selected-label', 'px-4', 'text-black'])
expect(
Select.computed.selectStyles.call({
internalValue: undefined, // unlikely
})
).toEqual(['selected-label', 'px-4', 'text-black'])
})
Tyia!