Skip to content

Commit

Permalink
add checking content is not there
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 12, 2024
1 parent 6f6510e commit 7e7b03f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/recipes/pseudo-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,54 @@ cy.get('[data-cy=after-example] p')

<!-- fiddle-end -->

### Checking if `::after` exists or not

<!-- fiddle pseudo-selectors / check if after pseudo element exists or not -->

```html hide
<style>
/* add a word after each paragraph */
[data-cy='after-example'] p::after {
margin-left: 1em;
}
[data-cy='after-example'] p.displayed::after {
content: 'Joe and Amy';
}
</style>
<div data-cy="after-example">
<p>Write more tests</p>
<button id="add-after">Click me</button>
</div>
<script>
document
.getElementById('add-after')
.addEventListener('click', () => {
setTimeout(() => {
const el = document.querySelector(
"[data-cy='after-example'] p",
)
el.classList.add('displayed')
}, 1000)
})
</script>
```

```js
cy.log('**no ::after at first**')
cy.get('[data-cy=after-example] p')
.applyToFirstRight(window.getComputedStyle, '::after')
.invoke('getPropertyValue', 'content')
.should('equal', 'none')
cy.contains('button', 'Click me').click()
cy.log('**new ::after content after some time**')
cy.get('[data-cy=after-example] p')
.applyToFirstRight(window.getComputedStyle, '::after')
.invoke('getPropertyValue', 'content')
.should('equal', '"Joe and Amy"')
```

<!-- fiddle-end -->

## Before content CSS selector `::before`

<!-- fiddle pseudo-selectors / before selector -->
Expand Down

0 comments on commit 7e7b03f

Please sign in to comment.