最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - _locale.cy.request is not a function - Stack Overflow

programmeradmin2浏览0评论

I'm trying to create a basic login command in Cypress, which was working when I used cy.visit().

After reading up on Cypress, I found out that logging in using the UI is an anti-pattern, so I'm attempting to switch over to calling cy.request() to post to the login route.

However, when I try this, I get an error that does not make sense to me:

TypeError: _locale.cy.request is not a function

This is my code in commands.js:

Cypress.Commands.add("login", () => {
  cy.request('POST', `${Cypress.config().baseUrl}/login`, {username: 'sysadmin', password: 'test'});
});

And this is where it gets called in the test:

it('Logs in successfully', () => {
  cy.login();
});

From my understanding, cy.request is a function that comes with Cypress, that can take in a method, url and body: .html#Syntax.

Can anyone please explain why Cypress isn't recognizing its own native function?

Thanks

I'm trying to create a basic login command in Cypress, which was working when I used cy.visit().

After reading up on Cypress, I found out that logging in using the UI is an anti-pattern, so I'm attempting to switch over to calling cy.request() to post to the login route.

However, when I try this, I get an error that does not make sense to me:

TypeError: _locale.cy.request is not a function

This is my code in commands.js:

Cypress.Commands.add("login", () => {
  cy.request('POST', `${Cypress.config().baseUrl}/login`, {username: 'sysadmin', password: 'test'});
});

And this is where it gets called in the test:

it('Logs in successfully', () => {
  cy.login();
});

From my understanding, cy.request is a function that comes with Cypress, that can take in a method, url and body: https://docs.cypress.io/api/commands/request.html#Syntax.

Can anyone please explain why Cypress isn't recognizing its own native function?

Thanks

Share Improve this question asked Feb 18, 2020 at 16:33 PepPep 3892 gold badges8 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 23

Old question, i had the same problem, but my solution was to simply ensure that there was no import { cy } from 'date-fns/locale'; at the top of your page.

发布评论

评论列表(0)

  1. 暂无评论