Skip to content

Commit

Permalink
Add window.prompt stubbing example to api section (#294)
Browse files Browse the repository at this point in the history
* Add window.prompt stubbing example to api

* remove semicolons
  • Loading branch information
microbouji authored and bahmutov committed Dec 2, 2017
1 parent bc33894 commit 59f8b3c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/api/commands/stub.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ App.stop()
expect(removeStub).to.be.called
```

***Replace built-in window methods like prompt***
```javascript
// assume App.start uses prompt to set the value of an element with class "name"
cy.visit('http://localhost:3000', {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('my custom message')
}
})

App.start()

cy.window().its('prompt').should('be.called')
cy.get('.name').should('have.value', 'my custom message')
```

***Using cy.stub***

{% note info %}
Expand Down

0 comments on commit 59f8b3c

Please sign in to comment.