salix-front/test/cypress/components/FetchData.spec.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

/// <reference types="cypress" />
2024-10-18 11:51:41 +00:00
import axios from 'axios';
2024-09-26 23:03:59 +00:00
import FetchData from 'src/components/FetchData.vue';
2024-10-18 06:32:48 +00:00
describe.only('<FetchData />', () => {
const mockApiResponse = { results: [{ id: 1, name: 'Test' }] };
2024-10-18 11:51:41 +00:00
const url = '/api/Schemas/modelinfo';
it('Autoload: true', () => {
2024-09-26 23:03:59 +00:00
// see: https://on.cypress.io/mounting-vue
2024-10-18 11:51:41 +00:00
cy.stub(axios, 'get').resolves({ data: mockApiResponse }).as('axiosStub');
2024-10-18 06:32:48 +00:00
const onFetchSpy = cy.spy().as('onFetchSpy');
cy.createWrapper(FetchData, {
props: {
autoLoad: true,
2024-10-18 11:51:41 +00:00
url,
2024-10-18 06:32:48 +00:00
},
emits: { onFetch: onFetchSpy },
});
2024-10-18 11:51:41 +00:00
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);
});
2024-10-18 06:32:48 +00:00
});
2024-10-18 11:51:41 +00:00
it('Autoload: false', () => {
2024-10-18 06:32:48 +00:00
// see: https://on.cypress.io/mounting-vue
2024-10-18 11:51:41 +00:00
cy.stub(axios, 'get').resolves({ data: mockApiResponse }).as('axiosStub');
const onFetchSpy = cy.spy().as('onFetchSpy');
2024-10-18 06:32:48 +00:00
cy.createWrapper(FetchData, {
props: {
autoLoad: false,
2024-10-18 11:51:41 +00:00
url,
2024-10-18 06:32:48 +00:00
},
2024-10-18 11:51:41 +00:00
emits: { onFetch: onFetchSpy },
2024-10-18 06:32:48 +00:00
});
2024-10-18 11:51:41 +00:00
cy.get('@onFetchSpy').should('not.to.have.been.called');
2024-09-26 23:03:59 +00:00
});
});