question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running .should('have.attr', 'target') and then .invoke('removeAttr', 'target') fails.

See original GitHub issue

Current behavior:

Running .should('have.attr', 'target) and right after I run .invoke('removeAttr', 'target') will failed.

cypress-should

Desired behavior:

Should run the check if attribute target exist and I should be able to remove it after.

Test code to reproduce

it.only('has a link to application author', () => {
  cy
      .get('.my-link')
      .should('have.attr', 'target')
      .invoke('removeAttr', 'target')
});

Versions

Cypress: “cypress”: "^5.1.0 OS: Ubuntu 20.04.1 LTS Browser: Chrome Version 85.0.4183.102 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bahmutovcommented, Sep 29, 2020

A few more tested examples for changing the subject in the few assertions is here https://glebbahmutov.com/cypress-examples/commands/assertions.html#subject

Maybe I should add them to the docs @jennifer-shehane

1reaction
nicholaschiangcommented, Sep 29, 2020

Yeah, add that to the assertions reference (it seems like you’re already mentioning it here). Otherwise, this seems like a bug and can be confusing.

Also, you should update the Typescript types to reflect this. Right now, chaining a .then() off of a .should() expects an HTMLElement:

cy.get('#hello').should('have.attr', 'id').then((attr: string) => { // This errors because it's typed as an `HTMLElement` not `string`
  // Do something with that `attr`
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

cypress invoke('removeAttr', 'target') not working
Is failing because you have this assertion .should('have.attr', 'target') before this invocation .invoke('removeAttr', 'target') .
Read more >
cypress-io/cypress - Gitter
invoke ('removeAttr' , 'target') not working, so can anyone provide me ... but cypress will only run the last module.export file so if...
Read more >
invoke
Send specific arguments to the function · Use cy.invoke('removeAttr', 'target') to get around new tab · Arguments are automatically forwarded to the function....
Read more >
Cypress invoke command
Now here we have used the invoke-command and used the JQuery function remove attribute to remove target to focus on the new site...
Read more >
Cypress INVOKE Review: A Command you MUST KNOW
Learn what is Cypress Invoke and WHEN you should use it.#cypress #testing #javascript⏰Timestamps: 00:00​​​​ - Video Introduction02:25 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found