samedi 22 février 2020

How to access Vue-test-util console error

I am using Jest to test this Vue component:

import { mount } from '@vue/test-utils'
import ExampleComponent from '../Components/Example.vue'

describe("Test", () => {
    it('shows no errors', () => {
        jest.spyOn(global.console, 'error');
        jest.spyOn(global.console, 'warn');

        mount(ExampleComponent)

        expect(console.warn).not.toHaveBeenCalled()
        expect(console.error).not.toHaveBeenCalled()
    })
})

I am expecting this test to Fail since I have this component:

Example.vue

<template>
    <div>
        
    </div>
</template>

<script>
export default {}
</script>

as you can see number is not defined, and if opened this component using the browser it will show me:

[Vue warn]: Property or method "number" is not defined on the instance but referenced during render.

but if I test it, the test will pass. How can If the Vue component has warnings or errors?

Aucun commentaire:

Enregistrer un commentaire