Methods
(static) hasBoundProps(component, boundProps) → {boolean}
Checks if an instance of a component has the specified bound props.
Parameters:
Name | Type | Description |
---|---|---|
component |
Component |
An instance of a component |
boundProps |
Array | Object |
The bound props to check |
- Source:
Examples
<script>
import Component from './Component.svelte'
</script>
<Component bind:first=firstValue bind:second=secondValue />
// Import mocked components
jest.mock('Component.svelte');
import Component from 'Component.svelte';
svelteMock.mockImplementation(Component);
// Import and render app
import App from 'App.svelte';
new App();
// Get instance of component
const component = Component.getInstanceByBoundProps(['first', 'second']);
hasBoundProps(component, ['first']); // true
hasBoundProps(component, ['first', 'second']); // true
hasBoundProps(component, ['nonExistent'])); // false
hasBoundProps(component, { first: firstValue }); // true
hasBoundProps(component, { first: wrongValue }); // false
(static) hasEventHandlers(component, eventHandlers) → {boolean}
Checks if an instance of a component has the specified event handlers.
Parameters:
Name | Type | Description |
---|---|---|
component |
Component |
An instance of a component |
eventHandlers |
Array | Object |
The event handlers to check |
Examples
<script>
import Component from './Component.svelte'
</script>
<Component on:click="clickFn()" on:custom="customFn()" />
// Import mocked components
jest.mock('Component.svelte');
import Component from 'Component.svelte';
svelteMock.mockImplementation(Component);
// Import and render app
import App from 'App.svelte';
new App();
// Get instance of component
const component = Component.getInstanceByEventHandlers(['click']);
hasEventHandlers(component, ['click']); // true
hasEventHandlers(component, ['click', 'customFn']); // true
hasEventHandlers(component, ['nonExistent'])); // false
hasEventHandlers(component, { click: clickFn }); // true
hasEventHandlers(component, { click: wrongFn }); // false
(static) hasProps(component, props) → {boolean}
Checks if an instance of a component has the specified props.
Parameters:
Name | Type | Description |
---|---|---|
component |
Component |
An instance of a component |
props |
Array | Object |
The props to check |
- Source:
Examples
<script>
import Component from './Component.svelte'
</script>
<Component first=firstValue second=secondValue />
// Import mocked components
jest.mock('Component.svelte');
import Component from 'Component.svelte';
svelteMock.mockImplementation(Component);
// Import and render app
import App from 'App.svelte';
new App();
// Get instance of component
const component = Component.getInstanceByProps(['first', 'second']);
hasProps(component, ['first']); // true
hasProps(component, ['first', 'second']); // true
hasProps(component, ['nonExistent'])); // false
hasProps(component, { first: firstValue }); // true
hasProps(component, { first: wrongValue }); // false
(static) hasSlots(component, slotsopt) → {boolean}
Checks if an instance of a component has the specified slots.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
component |
Component |
An instance of a component |
|
slots |
Array | Object |
<optional> |
The slots to check. Default/unnamed slot is checked if this parameter is not provided. |
- Source:
Examples
<script>
import Component from './Component.svelte'
</script>
<Component id="component1">
<span>First</span>
</Component>
<Component id="component2">
<span slot="first">First</span>
<span slot="second">Second</span>
</Component>
// Import mocked components
jest.mock('Component.svelte');
import Component from 'Component.svelte';
svelteMock.mockImplementation(Component);
// Import and render app
import App from 'App.svelte';
new App();
// Get instance of component
const component1 = Component.getInstanceByProps({ id: 'component1' });
const component2 = Component.getInstanceByProps({ id: 'component2' });
// Check for unnamed slot
hasSlots(component1); // true
// Check for named slots
hasSlots(component2, ['first']); // true
hasSlots(component2, ['first', 'second']); // true
hasSlots(component2, ['nonExistent'])); // false
hasSlots(component2, { first: firstSlot }); // true
hasSlots(component2, { first: wrongSlot }); // false