0

I have a NuxtJS project.

I want to use Cypress component testing.

When I try to run my first test, on rendering component I got an error:

this.$axios.$get('/api/account/')

this.$axios - is undefined

I have same error on try to call

this.$bus.$on 

this.$bus - is undefined

The problem is: on running NuxtJS component testing, cypress doesn't use my original nuxt.config.js. and not include NuxtJS plugins and NuxtJS modules.

My package.json file is:

{
    "private": true,
    "scripts": {
        "dev": "NODE_OPTIONS=--openssl-legacy-provider nuxt -c client/nuxt.config.js",
        "dev-php": "php artisan serve --port=3000",
        "build": "nuxt build -c client/nuxt.config.js",
        "build-temporary-folder": "nuxt build -c client/nuxt.config.temporary.js",
        "start": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt start -c client/nuxt.config.js",
        "generate": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt generate -c client/nuxt.config.js",
        "lint": "eslint --ext .js,.vue --fix client/",
        "check": "npm run lint",
        "test": "node ./tests.js",
        "cypress:open": "cypress open --config-file client/cypress.config.js",
        "cypress:run": "cypress run"
    },
    "prettier": {
        "singleQuote": true,
        "arrowParens": "avoid"
    },
    "dependencies": {
        "@babel/core": "^7.13.10",
        "@babel/plugin-syntax-dynamic-import": "^7.8.3",
        "@babel/runtime": "^7.13.10",
        "@nuxtjs/axios": "^5.13.1",
        "@nuxtjs/google-analytics": "^2.4.0",
        "@nuxtjs/proxy": "^2.1.0",
        "@nuxtjs/router": "^1.6.1",
        "@nuxtjs/sentry": "^4.0.0",
        "@nuxtjs/vuetify": "^1.12.1",
        "ajv": "^6.6.2",
        "axios": "^0.27.2",
        "axios-case-converter": "^0.11.1",
        "babel-runtime": "^6.26.0",
        "cssnano": "^4.1.10",
        "cssnano-preset-advanced": "^4.0.7",
        "dotenv": "^4.0.0",
        "fs-extra": "^8.1.0",
        "getcomposer": "^1.3.3",
        "intersection-observer": "^0.7.0",
        "js-cookie": "^2.2.0",
        "lodash": "^4.17.11",
        "nuxt": "^2.15.8",
        "nuxt-polyfill": "^1.0.3",
        "sass-loader": "^10.1.1",
        "smoothscroll-polyfill": "^0.4.4",
        "url-polyfill": "^1.1.12",
        "vue-carousel": "^0.18.0",
        "vue-color-picker-wheel": "^0.4.3",
        "vue-i18n": "^8.17.0",
        "vue-lazy-hydration": "^1.0.0-beta.12",
        "vue-lazyload": "^1.3.3",
        "vue-scrollto": "^2.17.1",
        "vuetify": "^2.6.10",
        "vuex-router-sync": "^5.0.0"
    },
    "devDependencies": {
        "@cypress/webpack-dev-server": "^3.4.1",
        "@nuxtjs/eslint-config": "^6.0.0",
        "@prettier/plugin-php": "^0.16.2",
        "@vue/eslint-config-prettier": "^6.0.0",
        "babel-eslint": "^10.1.0",
        "change-object-case": "^0.2.0",
        "css-loader": "^5.1.3",
        "cypress": "^12.11.0",
        "cypress-nuxt": "^1.3.1",
        "cypress-vue-unit-test": "^3.5.1",
        "eslint": "^7.22.0",
        "eslint-config-airbnb": "^18.2.1",
        "eslint-config-prettier": "^8.1.0",
        "eslint-config-standard": "^16.0.2",
        "eslint-plugin-babel": "^5.3.1",
        "eslint-plugin-chai-friendly": "^0.4.1",
        "eslint-plugin-cypress": "^2.13.2",
        "eslint-plugin-html": "^6.1.2",
        "eslint-plugin-import": "^2.22.1",
        "eslint-plugin-jsx-a11y": "^6.2.3",
        "eslint-plugin-node": "^11.1.0",
        "eslint-plugin-prettier": "^3.3.1",
        "eslint-plugin-promise": "^4.2.1",
        "eslint-plugin-react": "^7.16.0",
        "eslint-plugin-standard": "^5.0.0",
        "eslint-plugin-vue": "^7.8.0",
        "eslint-plugin-you-dont-need-lodash-underscore": "^6.10.0",
        "husky": "^1.1.0",
        "imagemin-lint-staged": "^0.3.0",
        "lint-staged": "^7.3.0",
        "postcss": "^8.2.8",
        "postcss-import": "^13.0.0",
        "postcss-loader": "^4.2.0",
        "postcss-url": "^10.1.3",
        "prettier": "^2.4.1",
        "stylelint": "^13.12.0",
        "stylelint-config-prettier": "^8.0.2",
        "stylelint-config-standard": "^21.0.0",
        "stylelint-prettier": "^1.2.0",
        "stylelint-processor-html": "^1.0.0",
        "vue-eslint-parser": "^7.6.0"
    },
    "lint-staged": {
        "*.{vue,js}": [
            "eslint  --fix ",
            "git add"
        ],
        "*.{png,jpeg,jpg,gif,svg}": [
            "imagemin-lint-staged",
            "git add"
        ]
    }
}

How I can fix it?

I tried use https://www.npmjs.com/package/cypress-nuxt

But it didn't work.

0 Answers0