I am working on a unit test using vue-test-utils and Jest. The component that I'm testing has several images, but one is more important than others, which I'd like to test, to see if it is there.
I've looked at the docs [https://vue-test-utils.vuejs.org/guides/#getting-started] and [https://vue-test-utils.vuejs.org/api/wrapper/get.html]
Here is my code.
Component with the image:
<template>
<img :scr="require('./images/image1.png')" class="image1"/>
<!-- other code below - not testing in this case -->
</template>
My test:
import component from '@/src/stuff/component';
import { mount } from 'vue-test-utils';
describe('component', () => {
const wrapper = mount(component);
test('Is there an image in the component', () => {
const img = wrapper.find('.image1'))
expect(img.is('.image1')).toBe(true)
expect(wrapper.get('image1'))
});
My error is : "wrapper.get" is not a function.
I'd like to get some help to properly test if there is an image in my component, and how to work with the get() assertion in unit tests.
the code, that made my test work, that I used is:
test("Check that the specific image exists", () => {
const img = wrapper.findAll('.image1'));
expect(img.length).toBe(1);
});