Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
feat: automatically fail Cypress test on Vue-caught error
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 8, 2020
1 parent e543ea6 commit 604edfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cypress/component/basic/translated-message-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/// <reference types="cypress" />

// testing i18n component
// http://kazupon.github.io/vue-i18n
import TranslatedMessage from './TranslatedMessage.vue'
import VueI18n from 'vue-i18n'
import { mountCallback } from 'cypress-vue-unit-test'

/* eslint-env mocha */
// https://github.com/bahmutov/cypress-vue-unit-test/issues/332
describe.skip('VueI18n', () => {
// need to use VueI18n as a plugin
Expand Down
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ interface MountOptions {
*/
type MountOptionsArgument = Partial<ComponentOptions & MountOptions>

/**
* Direct Vue errors to the top error handler
* where they will fail Cypress test
* @see https://vuejs.org/v2/api/#errorHandler
* @see https://github.com/cypress-io/cypress/issues/7910
*/
function failTestOnVueError(err, vm, info) {
console.error(`Vue error 🔥`)
console.error(err)
console.error('component:', vm)
console.error('info:', info)
window.top.onerror(err)
}

/**
* Mounts a Vue component inside Cypress browser.
* @param {object} component imported from Vue file
Expand Down Expand Up @@ -351,6 +365,8 @@ export const mount = (
.then((win) => {
// @ts-ignore
win.Vue = Vue
// @ts-ignore
win.Vue.config.errorHandler = failTestOnVueError

// @ts-ignore
const document: Document = cy.state('document')
Expand Down

0 comments on commit 604edfa

Please sign in to comment.