Skip to content

Commit

Permalink
Merge pull request #498 from remarkablemark/feat/heading
Browse files Browse the repository at this point in the history
feat(assertions): add "Then I do not see heading"
  • Loading branch information
remarkablemark authored Oct 7, 2023
2 parents fc94318 + 1b4939f commit dbadb6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cypress/e2e/example/example.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Feature: Example
Then I see document title "Example Domain"
And I see document title contains "Example"

Scenario: See heading
Scenario: Heading
Given I visit "http://example.com/"
Then I see heading "Example Domain"
When I find headings by text "Example Domain"
Then I count 1 element
When I find heading by text "Example Domain"
Then I count 1 element
And I do not see heading "Foo"

Scenario: See and not see text
Scenario: Text
Given I visit "http://example.com/"
Then I see text "Example Domain"
And I see text "More information"
Expand Down
31 changes: 30 additions & 1 deletion src/assertions/heading.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Then } from '@badeball/cypress-cucumber-preprocessor';

import { When_I_find_heading_by_text } from '../queries';
import {
When_I_find_heading_by_text,
When_I_find_headings_by_text,
} from '../queries';
import { getCypressElement } from '../utils';

/**
Expand Down Expand Up @@ -30,3 +33,29 @@ export function Then_I_see_heading(text: string) {
}

Then('I see heading {string}', Then_I_see_heading);

/**
* Then I do not see heading:
*
* ```gherkin
* Then I do not see heading {string}
* ```
*
* Assert heading with text **_does not exist_** in the screen.
*
* @example
*
* ```gherkin
* Then I do not see heading "Heading"
* ```
*
* @see
*
* - {@link Then_I_do_not_see_text | Then I do not see text}
*/
export function Then_I_do_not_see_heading(text: string) {
When_I_find_headings_by_text(text);
getCypressElement().should('not.exist');
}

Then('I do not see heading {string}', Then_I_do_not_see_heading);

0 comments on commit dbadb6c

Please sign in to comment.