Giter VIP home page Giter VIP logo

Comments (4)

scottschafer avatar scottschafer commented on July 26, 2024 2

The first thing I would try would be to delete the recorded mock file and allow it to be regenerated.

If that doesn't work, I'm not really sure what to tell you. I am wondering if there's an issue with visit(), and if pages are actually being reloaded in this case. That might cause issues.

Another option would be to skip automocker for this case but possibly use it in other tests.

I wish I had a better answer and more time to look into this.

from cypressautomocker.

adieCodes avatar adieCodes commented on July 26, 2024

I'm having exactly the same issue having added this library. Anyone have any ideas of the issue?

from cypressautomocker.

scottschafer avatar scottschafer commented on July 26, 2024

If you comment out the before/after calls, does the same error occur?

Can you provide sample code that demonstrates the issue?

from cypressautomocker.

adieCodes avatar adieCodes commented on July 26, 2024

@scottschafer thanks for coming back to me and creating the plugin.

I've uncommented the before/after calls and the issue does not occur, leading me to believe the problem is with automocker.

For context, I have:

  • Installed cypressautomocker as a dependancy
  • importted and invoked installCypressHooks in the root component of my React app (React v16.3.2)
  • Imported and invoked registerAutoMockCommands in commands.js
  • Added the before and after blocks to my test files, the simplest example being:
/// <reference types="Cypress" />

describe('Login', () => {
  const username = 'testuser';
  const password = 'password`
  const MOCK_FILENAME = 'groupMock';

  before(() => {
    cy.automock(MOCK_FILENAME);
  });

  beforeEach(() => {
    cy.visit('/logout');
  });

  after(() => {
    cy.automockEnd();
  });

  it('Redirects to Dashboard after logging in', () => {
    cy.visit('/login');

    cy.get('[data-testid=username]').type(username);
    cy.get('[data-testid=password').type(password);
    cy.contains(/login/i).click();

    cy.url().should('contain', '/home');
  });

  it('Displays error if incorrect username', () => {
    cy.visit('/login');

    cy.get('[data-testid=username]').type(`${username}s`);
    cy.get('[data-testid=password]').type(password);
    cy.contains(/login/i).click();

    cy.contains('Username is invalid');
    cy.url().should('not.contain', '/home');
    cy.url().should('contain', '/login');
  });

  it('Displays error if incorrect password', () => {
    cy.visit('/login');

    cy.get('[data-testid=username]').type(username);
    cy.get('[data-testid=password').type(`${password}s`);
    cy.contains(/login/i).click();

    cy.contains('Password is incorrect');
    cy.url().should('not.contain', '/home');
    cy.url().should('contain', '/login');
  });

  it('Redirects when forgotten password clicked', () => {
    cy.visit('/login');

    cy.contains(/forgotten password/i).click();

    cy.url().should('contain', '/forgotten');
  });
});

Any help is greatly appreciated

from cypressautomocker.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.