'Using react-testing-library + jest, why is my code coverage so high despite no "expect"?
I'm attempting to up our test coverage in our app and am a bit confused about the combo of react-testing-library + jest and how they determine coverage.
I'm attempting to test one of our app's components using the following:
import React from 'react'
import { BrandColors } from '@components/settings/BrandColors'
import '@testing-library/jest-dom'
import { MockedProvider } from '@apollo/client/testing'
import { SettingsDocument } from '@generated/graphql'
import { render } from '@testing-library/react'
import { getMockResponse, schemaWithMocks } from '@utils/apollo-mocks'
it('shows a skeleton when loading', async () => {
const data = await getMockResponse(schemaWithMocks, SettingsDocument)
const mock = {
request: {
query: SettingsDocument
},
result: { data }
}
const { container } = render(
<MockedProvider mocks={[mock]}>
<BrandColors />
</MockedProvider>
)
})
I've been developing tests while running --watch so I get immediate feedback every time I save. I was surprised to see that what I wrote above immediately gave me 94% coverage on the <BrandColors> component despite no expect assertions.
What gives?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
