UNPKG

cypress-example-kitchensink

Version:

This is an example app used to showcase Cypress.io testing. For a full reference of our documentation, go to docs.cypress.io

199 lines (181 loc) 7.38 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="Kitchen Sink | Cypress Example"> <meta name="author" content="Cypress.io"> <meta name="copyright" content="Cypress.io Copyright (c) 2016"> <title>Cypress.io: Kitchen Sink</title> <link rel="icon" href="/assets/img/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="/assets/css/vendor/bootstrap.min.css"> <link rel="stylesheet" href="/assets/css/vendor/fira.css"> <link rel="stylesheet" href="/assets/css/styles.css"> </head> <body> <nav class="navbar navbar-inverse"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">cypress.io</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Commands <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="/commands/querying">Querying</a></li> <li><a href="/commands/traversal">Traversal</a></li> <li><a href="/commands/actions">Actions</a></li> <li><a href="/commands/window">Window</a></li> <li><a href="/commands/viewport">Viewport</a></li> <li><a href="/commands/location">Location</a></li> <li><a href="/commands/navigation">Navigation</a></li> <li><a href="/commands/assertions">Assertions</a></li> <li><a href="/commands/misc">Misc</a></li> <li><a href="/commands/connectors">Connectors</a></li> <li><a href="/commands/aliasing">Aliasing</a></li> <li><a href="/commands/waiting">Waiting</a></li> <li><a href="/commands/network-requests">Network Requests</a></li> <li><a href="/commands/fixtures">Fixtures</a></li> <li><a href="/commands/local-storage">Local Storage</a></li> <li><a href="/commands/cookies">Cookies</a></li> </ul> </li> <li><a href="/utilities">Utilities</a></li> <li> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Cypress API <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="/cypress-api/config">config</a></li> <li><a href="/cypress-api/env">env</a></li> <li><a href="/cypress-api/commands">Commands</a></li> <li><a href="/cypress-api/cookies">Cookies</a></li> <li><a href="/cypress-api/dom">Dom</a></li> <li><a href="/cypress-api/server">Server</a></li> </ul> </ul> </div> </div> </nav> <div class="banner"> <div class="container"> <h1>Assertions</h1> <p>Examples of asserting the state or behavior of your application in Cypress, for a full reference of commands, go to <a href="https://on.cypress.io/api" target="_blank">docs.cypress.io</a> </p> </div> </div> <div class="container content-container"> <div id="assertions"> <div class="row"> <div class="col-xs-12"> <h3>Implicit Assertions</h3> <hr> </div> <div class="col-xs-7"> <h4>cy.should()</h4> <p>To make an assertion about the current subject, use the <a href="https://on.cypress.io/api/should"><code>cy.should()</code></a> command.</p> <pre><code class="javascript">cy .get('.assertion-table') .find('tbody tr:last').should('have.class', 'success')</code></pre> </div> <div class="col-xs-5"> <div class="well"> <table class="table table-bordered assertion-table"> <thead> <tr> <th>#</th> <th>Column heading</th> <th>Column heading</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Column content</td> <td>Column content</td> </tr> <tr> <th scope="row">2</th> <td>Column content</td> <td>Column content</td> </tr> <tr class="success"> <th scope="row">3</th> <td>Column content</td> <td>Column content</td> </tr> </tbody> </table> </div> </div> <div class="col-xs-12"><hr></div> <div class="col-xs-7"> <h4>cy.and()</h4> <p>To chain multiple assertions together, use the <a href="https://on.cypress.io/api/and"><code>cy.and()</code></a> command.</p> <pre><code class="javascript">cy .get('.assertions-link') .should('have.class', 'active') .and('have.attr', 'href') .and('include', 'cypress.io')</code></pre> </div> <div class="col-xs-5"> <div class="well"> <a class="assertions-link active" href="http://docs.cypress.io">Cypress Docs</a> </div> </div> <div class="col-xs-12"><hr></div> <div class="col-xs-12"> <h3>Explicit Assertions</h3> <hr> </div> <div class="col-xs-7"> <h4>expect</h4> <p>To make an assertion about a specified subject, use <a href="https://on.cypress.io/guides/making-assertions"><code>expect</code></a>.</p> <pre><code class="javascript">// We can use Chai's BDD style assertions expect(true).to.be.true // Pass a function to should that can have any number // of explicit assertions within it. cy .get('.assertions-p').find('p') .should(function($p){ // return an array of texts from all of the p's var texts = $p.map(function(i, el){ // http://on.cypress.io/api/cypress-jquery return Cypress.$(el).text() }) // jquery map returns jquery object // and .get() convert this to simple array var texts = texts.get() // array should have length of 3 expect(texts).to.have.length(3) // set this specific subject expect(texts).to.deep.eq([ 'Some text from first p', 'More text from second p', 'And even more text from third p' ]) })</code></pre> </div> <div class="col-xs-5"> <div class="well"> <div class='assertions-p'> <p>Some text from first p</p> <p>More text from second p</p> <p>And even more text from third p</p> </div> </div> </div> <div class="col-xs-12"><hr></div> </div> </div> </div> <script src="/assets/js/vendor/jquery-1.12.0.min.js"></script> <script src="/assets/js/vendor/bootstrap.min.js"></script> <script src="/assets/js/vendor/highlight.pack.js"></script> <script src="/assets/js/scripts.js"></script> </body> </html>