Link Search Menu Expand Document

Cypress Command: clickCodeBlock

Summary

cy.clickCodeBlock($codeBlock) - Click the given code block to run its command and then validate the command return a zero status or behaves as annotated

Parameters

  • $codeBlock - The jQuery-wrapped executable code block to click on, as provied by cy.get()

Examples

cy.contains("a code substring")
  .then($codeBlock => cy.clickCodeBlock($codeBlock));
cy.get(...)
  .then($codeBlock => cy.clickCodeBlock($codeBlock));

Waiting

This command will wait until the command completes, unless otherwise specified by annotations.

Verification

This command will verify that the shell command succeeds, unless otherwise specified by annotations.

If the code block contains multiple commands, only the exit status of the last command will be checked for success. Authors are encouraged to use && to connect shell commands when there are multiple in a single block so that output from a subsequent command will not obscure the failure of a prior command.

Instruction-Guided

This is an instruction-guided command: By using this command to ask Cypress to click on a code block rather than typing directly into the terminal with terminalType, you will avoid having to remember to update your tests every time the contents of the code block changes.