diff --git a/source/api/events/on.md b/source/api/events/on.md deleted file mode 100644 index 81527da5b2..0000000000 --- a/source/api/events/on.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: on -comments: false ---- - -Attach a callback function to a {% url 'Cypress event' catalog-of-events %}. The callback will be invoked whenever the event is fired. - -# Syntax - -```javascript -Cypress.on(eventName, callbackFn) -cy.on(eventName, callbackFn) -``` - -## Usage - -**{% fa fa-check-circle green %} Correct Usage** - -```javascript -Cypress.on('fail', function(err) {}) // not automatically unbound between tests -cy.on('fail', function(err) {}) // automatically unbound between tests -``` - -## Arguments - -**{% fa fa-angle-right %} eventName** ***(String)*** - -The name of the event to listen to. Available events can be found {% url 'here' catalog-of-events %}. - -**{% fa fa-angle-right %} callbackFn** ***(Function)*** - -Pass a function that takes the event's arguments. - -# Examples - -## Listen to Events - -***Test that exceptions are handled properly*** -```js -it('handles exception', function(done) { - cy.on('uncaught:exception', function(err, runnable) { - expect(err.message).to.eq('Danger, Will Robinson!') - return done() - }) - cy.visit('/some-page-with-uncaught-exception.html') -}) -``` - -***On uncaught exception*** - -```js -Cypress.on('uncaught:exception', function(err, runnable) { - // if you return false from an uncaught:exception handler - // then the uncaught exception error will not be - // thrown or cause the test to fail - return false -}) -``` - -***On window.confirm*** - -```js -cy.on('window:confirm', function(msg) { - if (msg === 'Are you sure?') { - return true - } else { - return false - } -}) -``` - -***On test failure*** - -```js -it('did fail', function(done) { - cy.on('fail', function(err, runnable) { - expect(err).to.eq('Oops, there was a problem.') - return done() - }) - - cy.visit('/') - cy.get('some-element-that-doesnt-exist') -}) -``` - -# See also - -- {% url 'Catalog of Events' catalog-of-events %} -- {% url '`once`' once %} -- {% url '`removeAllListeners`' removealllisteners %} -- {% url '`removeListener`' removelistener %} diff --git a/source/api/events/once.md b/source/api/events/once.md deleted file mode 100644 index 22902fae7b..0000000000 --- a/source/api/events/once.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: once -comments: false ---- - -Attach a callback function to a {% url 'Cypress event' catalog-of-events %}. The callback will be invoked whenever the event is fired. Just like {% url "on" on %}, but causes the callback function to only be invoked once before being removed. - -# Syntax - -```javascript -Cypress.once(eventName, callbackFn) -cy.once(eventName, callbackFn) -``` - -## Usage - -**{% fa fa-check-circle green %} Correct Usage** - -```javascript -Cypress.once('window:load', function(err) {}) // not automatically unbound between tests -cy.once('window:load', function(err) {}) // automatically unbound between tests -``` - -## Arguments - -**{% fa fa-angle-right %} eventName** ***(String)*** - -The name of the event to listen to. Available events can be found {% url 'here' catalog-of-events %}. - -**{% fa fa-angle-right %} callbackFn** ***(Function)*** - -Pass a function that takes the event's arguments. - -# Examples - -## Listen to Events - -***On first uncaught exception*** - -```js -Cypress.once('uncaught:exception', function(err, runnable) { - // if you return false from an uncaught:exception handler - // then the uncaught exception error will not be - // thrown or cause the test to fail - return false -}) -``` - -***On first test failure*** - -```js -it('did fail', function(done) { - cy.once('fail', function(err, runnable) { - expect(err).to.eq('Oops, there was a problem.') - return done() - }) - - cy.visit('/') - cy.get('some-element-that-doesnt-exist') -}) -``` - -# See also - -- {% url 'Catalog of Events' catalog-of-events %} -- {% url '`on`' on %} -- {% url '`removeAllListeners`' removealllisteners %} -- {% url '`removeListener`' removelistener %} diff --git a/source/api/events/removealllisteners.md b/source/api/events/removealllisteners.md deleted file mode 100644 index 21ddb3233a..0000000000 --- a/source/api/events/removealllisteners.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: removeAllListeners -comments: false ---- - -Remove all listener attached with {% url '`on`' on %} or {% url '`once`' once %} to a {% url 'Cypress event' catalog-of-events %}. - -# Syntax - -```javascript -Cypress.removeAllListeners() -cy.removeAllListeners() -Cypress.removeAllListeners(eventName) -cy.removeAllListeners(eventName) -``` - -## Usage - -**{% fa fa-check-circle green %} Correct Usage** - -```javascript -Cypress.on('fail', function(err) {}) -Cypress.removeAllListeners('fail') - -cy.on('window:load', function(err) {}) -cy.removeAllListeners() -``` - -## Arguments - -**{% fa fa-angle-right %} eventName** ***(String)*** - -The name of the event to have the listener removed from. Available events can be found {% url 'here' catalog-of-events %}. - -**{% fa fa-angle-right %} callbackFn** ***(Function)*** - -Pass a function that takes the event's arguments. - -# Examples - -## Remove all event listeners - -***On log added*** - -```js -getLog = function(log) { - // do what you want with log data here -}) - -Cypress.on('log:added', getLog) -Cypress.removeAllListeners('log:added') -``` - -# See also - -- {% url 'Catalog of Events' catalog-of-events %} -- {% url '`on`' on %} -- {% url '`once`' once %} -- {% url '`removeListener`' removelistener %} -- {% url '`removeAllListeners`' removealllisteners %} diff --git a/source/api/events/removelistener.md b/source/api/events/removelistener.md deleted file mode 100644 index 65532232b6..0000000000 --- a/source/api/events/removelistener.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: removeListener -comments: false ---- - -Remove a listener attached with {% url '`on`' on %} or {% url '`once`' once %} to a {% url 'Cypress event' catalog-of-events %}. - -# Syntax - -```javascript -Cypress.removeListener(eventName, callbackFn) -cy.removeListener(eventName, callbackFn) -``` - -## Usage - -**{% fa fa-check-circle green %} Correct Usage** - -```javascript -Cypress.on('fail', function(err) {}) -Cypress.removeListener('fail', function(err) {}) - -cy.on('window:load', function(err) {}) -cy.removeListener('window:load', function(err) {}) -``` - -## Arguments - -**{% fa fa-angle-right %} eventName** ***(String)*** - -The name of the event to have the listener removed from. Available events can be found {% url 'here' catalog-of-events %}. - -**{% fa fa-angle-right %} callbackFn** ***(Function)*** - -Pass a function that takes the event's arguments. - -# Examples - -## Remove event listener - -***On uncaught exception*** - -```js -stopUncaughtExceptions = function(err, runnable) { - // if you return false from an uncaught:exception handler - // then the uncaught exception error will not be - // thrown or cause the test to fail - return false -}) - -Cypress.on('uncaught:exception', stopUncaughtExceptions) -Cypress.removeListener('uncaught:exception', stopUncaughtExceptions) -``` - -# See also - -- {% url 'Catalog of Events' catalog-of-events %} -- {% url '`on`' on %} -- {% url '`once`' once %} -- {% url '`removeAllListeners`' removealllisteners %}