import axios from 'axios'; import FetchData from 'src/components/FetchData.vue'; describe.only('', () => { const mockApiResponse = { results: [{ id: 1, name: 'Test' }] }; const url = '/api/Schemas/modelinfo'; it('Autoload: true', () => { // see: https://on.cypress.io/mounting-vue cy.stub(axios, 'get').resolves({ data: mockApiResponse }).as('axiosStub'); const onFetchSpy = cy.spy().as('onFetchSpy'); cy.createWrapper(FetchData, { props: { autoLoad: true, url, }, emits: { onFetch: onFetchSpy }, }); cy.get('@axiosStub').should((spy) => { expect(spy).to.have.been.calledWith('/api/Schemas/modelinfo'); const [url, params] = spy.getCall(0).args; expect(url).to.equal('/api/Schemas/modelinfo'); expect(params).to.deep.equal({ params: { filter: '{}', }, }); }); /*cy.get('@onFetchSpy').should('have.been.calledWith', mockApiResponse);*/ cy.get('@onFetchSpy').should((spy) => { expect(spy).to.have.been.calledWith(mockApiResponse); }); }); it('Autoload: false', () => { // see: https://on.cypress.io/mounting-vue cy.stub(axios, 'get').resolves({ data: mockApiResponse }).as('axiosStub'); const onFetchSpy = cy.spy().as('onFetchSpy'); cy.createWrapper(FetchData, { props: { autoLoad: false, url, }, emits: { onFetch: onFetchSpy }, }); cy.get('@onFetchSpy').should('not.to.have.been.called'); }); });