Component tests pass while Component code is wrong

Viewed 41

I am facing a strange case. I have some code in a Component which is covered by test. In the test I mock the call to an external dependency. At some point in time I changed the dependency signature. Therefore the dependency call in the Component was wrong and TS build fails accordingly. But for some reason the test still passes.

The real code is more complicated as the dependency is a store action so I will try to make it simpler but relevant.

// dependency.ts

// previous signature was
// export async function convert(field: Field, unit: Unit)
// changed after tests written for Component
export async function convert(type: string, from: Unit, to: Unit, value) {\
  // await some BE call to convert
  return converted
}
// Component
import { convert } from './dependency'

get async convertedValue() {
  // Not sure if that would be correct but I try to simplify
  // The point here is that the call to `convert` is now wrong
  return await convert(field, unit) // corresponds to previous `convert` signature and now TS complains of course
}
// Component.spec.ts
describe('Component', () => {
  it('should display the converted value', async () => {
    const expected = '1234'
    convertMock = jest.fn().mockResolvedValueOnce(expected)
    
    const wrapper = mount(Component)
    // trigger the event that makes the call
    await wrapper.find('[data-test=input]').trigger('blur')
    await flushPromises() // from 'flush-promises package
    // expect the displayed text in the component is `expected`
    expect(wrapper.find('[data-test=displayed-value]').text()).toBe(expected)
 
  })
})

So I do not understand why Jest does not detect that the call to the mocked function is wrong and still passes

0 Answers
Related