svelte-jester
svelte-jester copied to clipboard
jest code coverage - uncovered lines
When i use jest --coverage
, all tests pass, but some branches do not reach 100% and produce uncovered lines.
Example from a boilerplate of mine.
To reproduce a very simple component:
button.svelte
<script lang="ts">
export let label = '';
</script>
<button>{label}</button>
button.test.ts
import { render } from '@testing-library/svelte'
import Button from '../views/components/button.svelte'
test('button - props', () => {
const label = 'Click';
const setLabel = 'New Label';
const { getByText, component } = render(Button, { label });
expect(() => getByText(label)).not.toThrow();
component.label = setLabel;
expect(() => getByText(setLabel)).not.toThrow();
component.label = undefined;
expect(() => getByText('undefined')).toThrow();
component.label = null;
expect(() => getByText('null')).toThrow();
delete component.label;
expect(() => getByText('null')).toThrow();
})
test('button - no prop', () => {
global.console.warn = jest.fn()
const { container } = render(Button);
expect(container.innerHTML).toBe('<div></div>')
expect(console.warn).toBeCalled()
})
test('button - false prop', () => {
global.console.warn = jest.fn()
const {container} = render(Button, { falseProp: false });
expect(container.innerHTML).toBe('<div></div>')
expect(console.warn).toBeCalled()
})
It's possible to increase the component's coverage, by introducing the following: button.svelte
<script lang="ts">
export let label = '';
$: cLabel = label || '';
</script>
{#if cLabel}
<button>{cLabel}</button>
{/if}
But even then one else path not taken remains. Which to me makes no sense at that point:
Using svelte-jester v1.5.0 Full setup can be found in this repo
I have same issue..
Can you please retry with the latest version and jest 27+?
Upgrading to 27 led to a lot of problems. I think i could resolve most of them, but the last problem depends on this issue being solved: https://github.com/mihar-22/svelte-jester/issues/25 As soon as this one is resolved i will try again.
So i have downloaded a copy of the current dev version and got it working. But sadly the problem remains.
The same has happen to me, specifically with the {#if}
blocks that do not have {:else}
.
Upgrading to 27 led to a lot of problems. I think i could resolve most of them, but the last problem depends on this issue being solved: https://github.com/mihar-22/svelte-jester/issues/25 As soon as this one is resolved i will try again.
#25 is resolved, already
Sorry, yes its resolved, BUT, the last few comments on #25 highlight that the next release 2.1.3 will completely fix it. I have used the current dev state for testing not 2.1.2. Anyhow, 27 sadly did not fix the problem.
Where do you guys think the problem is? I can't find a place in the code it could be. Maybe it's outside this project? Maybe svelte/compiler
?
I think so too. It is either jest or svelte.