Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'onBeforeLoad' in overrode 'visit' still not get called in latest v3.3.0 #4259

Closed
freewind opened this issue May 20, 2019 · 2 comments
Closed

Comments

@freewind
Copy link

freewind commented May 20, 2019

Cypress.Commands.overwrite("visit", (visit: typeof cy.visit, url: string) => {
  console.log('### visit', visit, url);
  visit(url, {
    onBeforeLoad: () => {
      console.log('### onBeforeLoad')
    }
  })
});
describe('cypress', () => {
  it('should using overrode cy.visit correctly', () => {
    cy.visit('https://example.cypress.io/');

    // if you comment the following line, `onBeforeLoad` in overrode visit will run
    cy.title().should('equal', 'Cypress.io: Kitchen Sink')
  })
})

The test passed, but no ### onBeforeLoad get printed.

You can try it in the small complete demo project: https://github.com/freewind-demos/typescript-cypress-overwrite-visit-onbeforeload-issue-demo

@jennifer-shehane
Copy link
Member

You need to make sure to always return the original function call for the overwrite command as specified in our docs: https://on.cypress.io/custom-commands#Overwrite-visit-command

Working example:

// commands.ts

Cypress.Commands.overwrite("visit", (visit: typeof cy.visit, url: string) => {
  console.log('### visit', visit, url);
  
  return visit(url, {
    onBeforeLoad: () => {
      console.log('### onBeforeLoad')
    }
  })
});
//hello_spec.ts

it('override onBeforeLoad in cy.visit correctly', () => {
  cy.visit('https://example.cypress.io/');
})

@freewind
Copy link
Author

freewind commented May 21, 2019

Thanks! Seems like it's the typing problem:

cypress/types/index.d.ts

Commands: {
  overwrite(name: string, fn: (...args: any[]) => void): void
  overwrite(name: string, options: CommandOptions, fn: (...args: any[]) => void): void
}

The fn has void return type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants