import axios from 'axios'; import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue'; import { useArrayData } from 'src/composables/useArrayData'; import { useArrayDataStore } from 'src/stores/useArrayDataStore'; // import { useRouter } from 'vue-router'; // import vueRouter from 'vue-router'; describe('', () => { const mockApiResponse = { results: [{ id: 1, name: 'Test' }] }; const arrayDataStore = useArrayDataStore(); const mockStoreData = { filter: {}, userFilter: {}, userParams: {}, url: 'mockUrl' }; before(() => { cy.login('developer'); // cy.stub(arrayDataStore, 'get').callsFake(() => 'asd'); cy.stub(arrayDataStore, 'get') .callsFake((e, fn) => (e = fn)) .as('update'); const arrayData = useArrayData('ArrayData', { url: 'mockUrl' }); cy.stub(arrayData).callsFake(() => ({ userParams: {}, userFilter: {}, order: {}, searchUrl: 'searchUrl', })); // cy.stub(vueRouter, 'useRouter').callsFake(() => ({ // push: () => {}, // replace: () => {}, // currentRoute: { // value: { // params: { // id: 1, // }, // meta: { moduleName: 'mockName' }, // matched: [{ path: 'mockName/list' }], // }, // }, // })); }); beforeEach(() => { // Stub del método get del store // cy.spy(useRouter(), 'replace'); // cy.spy(useRouter(), 'push'); }); it('should intercept axios.get for a specific route', () => { // Intercepta la llamada a axios.get para una ruta específica cy.stub(axios, 'get') .callsFake((url, params) => { if (url === 'Countries') { return Promise.resolve({ data: mockApiResponse }); } // Si la URL no coincide, llama al método original return axios.get.wrappedMethod(url, params); }) .as('axiosStub'); const onFetchSpy = cy.spy().as('onFetchSpy'); cy.createWrapper(CreateBankEntityForm, { props: { showEntityField: true, }, attrs: { onFetch: onFetchSpy, }, }); cy.get('@axiosStub').should((spy) => { expect(spy).to.have.been.calledWith('Countries'); }); cy.get('@onFetchSpy').should((spy) => { expect(spy).to.have.been.calledWith(mockApiResponse); }); // Verifica que los datos emitidos por el hijo son manejados por el padre // cy.get('p').should('contain', 'Datos recibidos:'); // Verifica que los datos se muestran en el DOM // cy.get('p').should('contain', 'Test'); // Verifica que el contenido de los datos es correcto }); });