Reputation: 118
I am trying to intercept a POST request but I'm getting the following error:
This is my test file code:
I've found a similar question:
cy.intercept is not a function Cypress test
That question was solved by upgrading the cypress version above v5.3. But I already have cypress version 6.14.15. The error is seemingly only replicating on the .Then()
part, which is weird because the cy.intercept function is called in the previous line of code and NOT in the .Then()
part. where is the problem exactly?
EDIT: here is the package.json file
{
"name": "test-project-v2",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.24.0",
"core-js": "^3.6.5",
"vue": "^3.0.0",
"vuex": "^4.0.0-0"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-e2e-cypress": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "^2.0.0-0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.0.0",
"prettier": "^2.2.1",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"typescript": "~3.9.3",
"vue-jest": "^5.0.0-0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/prettier"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
"env": {
"jest": true
}
}
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"jest": {
"preset": "@vue/cli-plugin-unit-jest",
"transform": {
"^.+\\.vue$": "vue-jest"
}
}
}
Upvotes: 1
Views: 1169
Reputation: 6312
I would do the assertion of the cy.intercept
route like so instead:
cy.wait('@dialog').should(response => {
expect(response.response.statusCode).to.eq(200);
});
You also have a typo in this code snippet in respose.body
:
cy.wait('@dialog').its('respose.body').should('have.Congrats');
I would also check your package.json
& your current Cypress
's version installed. Note that cy.intercept()
was introduced in Cypress 6.0.0
.
Upvotes: 2