-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested
Description
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
wallw-dev, shrink, alicantokdemir, matthieujabbour, tveronezi and 1 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested