From 3fa7fde39440869b4b8d40d6a4427dafffadac1b Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:11:16 +0100 Subject: [PATCH] tests: add `useNodesInitialized` test --- .../4-composables/useNodesInitialized.cy.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/cypress/component/4-composables/useNodesInitialized.cy.ts diff --git a/tests/cypress/component/4-composables/useNodesInitialized.cy.ts b/tests/cypress/component/4-composables/useNodesInitialized.cy.ts new file mode 100644 index 00000000..c31c5671 --- /dev/null +++ b/tests/cypress/component/4-composables/useNodesInitialized.cy.ts @@ -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) + }) +})