improve tests

This commit is contained in:
Rene Haas
2022-11-09 12:51:22 +01:00
parent e292e0e539
commit 6bd4acdedd
4 changed files with 21 additions and 17 deletions
@@ -1,13 +1,15 @@
import { describe, test, expect, vitest } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useState } from 'react';
import { describe, test, afterEach, expect, vitest } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { OverlayScrollbars } from 'overlayscrollbars';
import { OverlayScrollbarsComponent } from '~/overlayscrollbars-react';
import type { RefObject } from 'react';
import type { OverlayScrollbarsComponentRef } from '~/overlayscrollbars-react';
describe('OverlayScrollbarsComponent', () => {
afterEach(() => cleanup());
describe('correct rendering', () => {
test('correct root element with instance', () => {
const elementA = 'code';
@@ -1,11 +1,13 @@
import { useRef } from 'react';
import { describe, test, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { describe, test, afterEach, expect } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useOverlayScrollbars } from '~/overlayscrollbars-react';
import type { OverlayScrollbars } from 'overlayscrollbars';
describe('useOverlayScrollbars', () => {
afterEach(() => cleanup());
test('re-initialization', () => {
const Test = () => {
const instanceRef = useRef<OverlayScrollbars | null>(null);
@@ -1,11 +1,13 @@
import { onMounted, ref, toRefs } from 'vue';
import { describe, test, expect, vitest } from 'vitest';
import { describe, test, afterEach, expect, vitest } from 'vitest';
import { OverlayScrollbars } from 'overlayscrollbars';
import { fireEvent, render, screen } from '@testing-library/vue';
import { fireEvent, render, screen, cleanup } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import { OverlayScrollbarsComponent } from '~/overlayscrollbars-vue';
describe('OverlayScrollbarsComponent', () => {
afterEach(() => cleanup());
describe('correct rendering', () => {
test('correct root element with instance', async () => {
const elementA = 'code';
@@ -1,13 +1,15 @@
import { reactive, onMounted, ref, watch, toRaw, watchPostEffect } from 'vue';
import { describe, test, expect, vitest } from 'vitest';
import { render, screen } from '@testing-library/vue';
import { describe, test, afterEach, expect, vitest } from 'vitest';
import { render, screen, cleanup } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import { useOverlayScrollbars } from '~/overlayscrollbars-vue';
import type { PartialOptions, EventListeners, OverlayScrollbars } from 'overlayscrollbars';
describe('useOverlayScrollbars', () => {
afterEach(() => cleanup());
test('re-initialization', () => {
const { unmount } = render({
render({
setup() {
const instanceRef = ref<OverlayScrollbars | null>(null);
const [initialize, instance] = useOverlayScrollbars();
@@ -40,13 +42,12 @@ describe('useOverlayScrollbars', () => {
userEvent.click(initializeBtn);
expect(snapshot).toBe(initializeBtn.innerHTML);
unmount();
});
test('reactive params', async () => {
let osInstance: OverlayScrollbars;
const onUpdated = vitest.fn();
const { unmount } = render({
render({
setup() {
const div = ref<HTMLElement | null>(null);
const params = reactive<{ options?: PartialOptions; events?: EventListeners }>({});
@@ -91,13 +92,12 @@ describe('useOverlayScrollbars', () => {
expect(onUpdated).toHaveBeenCalledTimes(1);
expect(osInstance!.options().paddingAbsolute).toBe(true);
unmount();
});
test('ref params', async () => {
let osInstance: OverlayScrollbars;
const onUpdated = vitest.fn();
const { unmount } = render({
render({
setup() {
const div = ref<HTMLElement | null>(null);
const params = ref<{ options?: PartialOptions; events?: EventListeners }>({});
@@ -138,13 +138,12 @@ describe('useOverlayScrollbars', () => {
expect(onUpdated).toHaveBeenCalledTimes(1);
expect(osInstance!.options().paddingAbsolute).toBe(true);
unmount();
});
test('ref params fields', async () => {
let osInstance: OverlayScrollbars;
const onUpdated = vitest.fn();
const { unmount } = render({
render({
setup() {
const div = ref<HTMLElement | null>(null);
const options = ref<PartialOptions | undefined>();
@@ -189,6 +188,5 @@ describe('useOverlayScrollbars', () => {
expect(onUpdated).toHaveBeenCalledTimes(1);
expect(osInstance!.options().paddingAbsolute).toBe(true);
unmount();
});
});