salix-front/test/jest/__tests__/MyButton.spec.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-03-24 12:41:17 +00:00
import { describe, expect, it } from '@jest/globals';
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
import { mount, shallowMount } from '@vue/test-utils';
import { QBtn } from 'quasar';
import MyButton from './demo/MyButton';
// Specify here Quasar config you'll need to test your component
installQuasarPlugin();
describe('MyButton', () => {
2022-03-24 13:57:11 +00:00
it('has increment method', () => {
const wrapper = mount(MyButton);
const { vm } = wrapper;
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
expect(typeof vm.increment).toBe('function');
});
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
it('can check the inner text content', () => {
const wrapper = mount(MyButton);
const { vm } = wrapper;
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
expect(vm.$el.textContent).toContain('rocket muffin');
expect(wrapper.find('.content').text()).toContain('rocket muffin');
});
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
it('sets the correct default data', () => {
const wrapper = mount(MyButton);
const { vm } = wrapper;
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
expect(typeof vm.counter).toBe('number');
expect(vm.counter).toBe(0);
});
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
it('correctly updates counter when button is pressed', async () => {
const wrapper = shallowMount(MyButton);
const { vm } = wrapper;
2022-03-24 12:41:17 +00:00
2022-03-24 13:57:11 +00:00
const button = wrapper.findComponent(QBtn);
await button.trigger('click');
expect(vm.counter).toBe(1);
});
2022-03-24 12:41:17 +00:00
});