2

I have the following component test:

import AutoGeneratedPage from '../../../src/components/AutoGenerate/AutoGenerate.vue'; // <= note the absence of `.vue` extension, here we are importing the JS/TS part of a Double File Component
describe('AutoGenerated Page tests', () => {
  it('Auto generated page from JSON should contain all the UI Elements', () => {
    cy.mount(AutoGeneratedPage);
    cy.get('[data-test="toggle-setting-0"]').eq(false);
    cy.get('[data-test="toggle-setting-0"]').focus().click();
    cy.get('[data-test="toggle-setting-0"]').eq(true);
    cy.get('[data-test="dropdown-setting-3"]').should('have.text', 'Option 1');
    cy.get('[data-test="dropdown-setting-3"]').should('have.text', 'Option 2');
    cy.get('[data-test="dropdown-setting-3"]').should('have.text', 'Option 3');
  });
})

and bump into the following error when running the component test: What do I miss? https://github.com/khteh/quasar enter image description here

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85

2 Answers2

0

The first assertion needs changing:

cy.get('[data-test="toggle-setting-0"]').eq(false);
cy.get('[data-test="toggle-setting-0"]').focus().click();
cy.get('[data-test="toggle-setting-0"]').eq(true);

change to

cy.get('[data-test="toggle-setting-0"]').invoke('val').should('eq', false);
cy.get('[data-test="toggle-setting-0"]').focus().click();
cy.get('[data-test="toggle-setting-0"]').invoke('val').should('eq', true);

because .eq(number) is a Cypress command for taking the nth item in a group.


The error Cannot read properties of undefined (reading 'deep') is due to the deep rendering (i.e nested components) in the AutoGenerate.vue component.

If you comment out the child components, the test succeeds.

<div v-for="(field, index) in layoutObj.data" :key="index">
  <span>{{field.name}}</span>
  <!-- <toggle-setting
    v-if="field.type === 'toggle'"
    :name="field.name"
    :fieldName="field.fieldName"
    :description="field.description"
    :data-test="`toggle-setting-${index}`"
  />
  <pop-up-edit-setting
    v-if="field.type === 'popUpEdit'"
    :dataType="field.dataType"
    :name="field.name"
    :fieldName="field.fieldName"
    :hint="field.hint"
    :data-test="`popup-edit-setting-${index}`"
  />
  <drop-down-setting
    v-if="field.type === 'dropDown'"
    :name="field.name"
    :description="field.description"
    :fieldName="field.fieldName"
    :internalOptions="internalOptions"
    :data-test="`dropdown-setting-${index}`"
  /> -->
</div>

Of course, the child components are required, but I thought I'd post this in case it gives you clues.

In any case, the Cypress component test is configured correctly, this is the config I used.

const { defineConfig } = require("cypress");
const webpackConfig = require("./webpack.config");

module.exports = defineConfig({
  e2e: {
    ...
  },
  component: {
    devServer: {
      framework: "vue",
      bundler: "webpack",      
      webpackConfig,
    },
    specPattern: 'test/cypress/components/**/*.cy.{js,jsx,ts,tsx}',
    indexHtmlFile: 'test/cypress/support/component-index.html',
  },
});

Will add to this if I find out the problem with deep-nested components.

Fody
  • 23,754
  • 3
  • 20
  • 37
0

Remove mount() and all references to quasar UI stuff. mount() must only be used for Component Tests. Not E2E tests.

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85