tests: add useNodesInitialized test

This commit is contained in:
braks
2024-02-05 16:11:16 +01:00
committed by Braks
parent c8c77a2967
commit 3fa7fde394

View File

@@ -0,0 +1,56 @@
import { defineComponent, h, watch } from 'vue'
import { useNodesInitialized } from '@vue-flow/core'
import { getElements } from '../../utils'
const { nodes } = getElements()
const ComposableTester = defineComponent({
emits: ['change'],
setup(_, { emit }) {
const nodesInitialized = useNodesInitialized()
watch(
nodesInitialized,
(value) => {
emit('change', value)
},
{ immediate: true },
)
return 'Composable Tester'
},
})
describe('Composable: `useNodesInitialized`', () => {
it('should return that nodes are initialized', () => {
const onChangeSpy = cy.spy().as('onChangeSpy')
cy.vueFlow(
{
nodes,
},
{},
{
default: () => h(ComposableTester, { onChange: onChangeSpy }),
},
)
cy.get('@onChangeSpy').should('have.been.calledWith', true)
})
it('should return that nodes are not initialized', () => {
const onChangeSpy = cy.spy().as('onChangeSpy')
cy.vueFlow(
{
nodes: [],
},
{},
{
default: () => h(ComposableTester, { onChange: onChangeSpy }),
},
)
cy.get('@onChangeSpy').should('have.been.calledWith', false)
})
})