diff --git a/source/guides/core-concepts/writing-and-organizing-tests.md b/source/guides/core-concepts/writing-and-organizing-tests.md index 529ce97f11..b83b4480cb 100644 --- a/source/guides/core-concepts/writing-and-organizing-tests.md +++ b/source/guides/core-concepts/writing-and-organizing-tests.md @@ -391,7 +391,7 @@ The code above will produce a suite with 4 tests: ## Assertion Styles -Cypress supports both BDD (`expect`/`should`) and TDD (`assert`) style assertions. {% url "Read more about assertions." assertions %} +Cypress supports both BDD (`expect`/`should`) and TDD (`assert`) style plain assertions. {% url "Read more about plain assertions." assertions %} ```javascript it('can add numbers', () => { @@ -403,6 +403,39 @@ it('can subtract numbers', () => { }) ``` +The {% url "`.should()`" should %} command and its alias {% url "`.and()`" and %} can also be used to more easily chain assertions off of Cypress commands. {% url "Read more about assertions." introduction-to-cypress#Assertions %} + +```js +cy.wrap(add(1, 2)).should('equal', 3) +``` + +# Running tests + +## Run a single spec file + +We suggest running test files individually by clicking on the spec filename to ensure the best performance. For example the {% url "Cypress RealWorld App" https://github.com/cypress-io/cypress-example-realworld %} has multiple test files, but below we run a single "new-transaction.spec.ts" test file. + +{% imgTag /img/guides/core-concepts/run-single-spec.gif "Running a single spec" %} + +## Run all specs + +You can run all spec files together by clicking the "Run all specs" button. This mode is equivalent to concatenating all spec files together into a single piece of test code. + +{% imgTag /img/guides/core-concepts/run-all-specs.gif "Running all specs" %} + +{% note danger %} +{% fa fa-warning %} Be wary of root-level hooks, as they could execute in a surprising order when clicking the "Run all specs" button. Instead place them inside `describe` or `context` suites for isolation. Read {% url "'Be careful when running all specs together'" https://glebbahmutov.com/blog/run-all-specs/ %}. +{% endnote %} + +## Run filtered specs + +You can also run a subset of all specs by entering a text search filter. Only the specs with relative file paths containing the search filter will remain and be run as if concatenating all spec files together when clicking the "Run N specs" button. + +- The search filter is case-insensitive; the filter "ui" will match both "UI-spec.js" and "admin-ui-spec.js" files. +- The search filter is applied to the entire relative spec file path, thus you can use folder names to limit the specs; the filter "ui" will match both "admin-ui.spec.js" and "ui/admin.spec.js" files. + +{% imgTag /img/guides/core-concepts/run-selected-specs.gif "Running specs matching the search filter" %} + # Watching tests When running in using {% url "`cypress open`" command-line#cypress-open %}, Cypress watches the filesystem for changes to your spec files. Soon after adding or updating a test Cypress will reload it and run all of the tests in that spec file. diff --git a/themes/cypress/source/img/guides/core-concepts/run-all-specs.gif b/themes/cypress/source/img/guides/core-concepts/run-all-specs.gif new file mode 100644 index 0000000000..7db2cb0458 Binary files /dev/null and b/themes/cypress/source/img/guides/core-concepts/run-all-specs.gif differ diff --git a/themes/cypress/source/img/guides/core-concepts/run-selected-specs.gif b/themes/cypress/source/img/guides/core-concepts/run-selected-specs.gif new file mode 100644 index 0000000000..1afbbdee8b Binary files /dev/null and b/themes/cypress/source/img/guides/core-concepts/run-selected-specs.gif differ diff --git a/themes/cypress/source/img/guides/core-concepts/run-single-spec.gif b/themes/cypress/source/img/guides/core-concepts/run-single-spec.gif new file mode 100644 index 0000000000..359383ea23 Binary files /dev/null and b/themes/cypress/source/img/guides/core-concepts/run-single-spec.gif differ