@featherds/composables
Advanced tools
Comparing version 0.12.5 to 0.12.6
import { useOutsideClick } from "./OutsideClick"; | ||
import { mount } from "@vue/test-utils"; | ||
import { ref, nextTick } from "vue"; | ||
import { vi, expect, describe, it } from "vitest"; | ||
const createWrapper = (setup) => { | ||
@@ -14,4 +14,4 @@ return mount({ | ||
it("should only attach listeners when element and active", async () => { | ||
const windowSpy = jest.spyOn(window, "addEventListener"); | ||
const documentSpy = jest.spyOn(document, "addEventListener"); | ||
const windowSpy = vi.spyOn(window, "addEventListener"); | ||
const documentSpy = vi.spyOn(document, "addEventListener"); | ||
const el = document.createElement("div"); | ||
@@ -22,3 +22,3 @@ document.body.appendChild(el); | ||
const wrapper = createWrapper(() => { | ||
active = useOutsideClick(elRef, jest.fn()); | ||
active = useOutsideClick(elRef, vi.fn()); | ||
}); | ||
@@ -31,6 +31,2 @@ await nextTick(); | ||
await nextTick(); | ||
expect(windowSpy).not.toHaveBeenCalled(); | ||
expect(documentSpy).not.toHaveBeenCalled(); | ||
await nextTick(); | ||
expect(windowSpy).toHaveBeenCalled(); | ||
@@ -40,6 +36,7 @@ expect(documentSpy).toHaveBeenCalled(); | ||
it("should only call callback when an element outside is clicked", async () => { | ||
const el = document.createElement("div.test"); | ||
const el = document.createElement("div"); | ||
el.classList.add("test"); | ||
document.body.appendChild(el); | ||
const elRef = ref(el); | ||
const listener = jest.fn(); | ||
const listener = vi.fn(); | ||
const wrapper = createWrapper(() => { | ||
@@ -52,3 +49,2 @@ const active = useOutsideClick(elRef, listener); | ||
let event = new MouseEvent("click", { | ||
view: window, | ||
bubbles: true, | ||
@@ -64,15 +60,15 @@ cancelable: false, | ||
event = new MouseEvent("click", { | ||
view: window, | ||
bubbles: true, | ||
cancelable: false, | ||
}); | ||
wrapper.find("div.test").element.dispatchEvent(event); | ||
console.log(document.body.innerHTML); | ||
document.querySelector("div.test").dispatchEvent(event); | ||
await nextTick(); | ||
expect(listener).toHaveBeenCalledTimes(2); | ||
expect(listener).toHaveBeenCalledTimes(1); | ||
}); | ||
it("should remove listeners when active is false", async () => { | ||
const windowSpy = jest.spyOn(window, "removeEventListener"); | ||
const documentSpy = jest.spyOn(document, "removeEventListener"); | ||
const windowSpy = vi.spyOn(window, "removeEventListener"); | ||
const documentSpy = vi.spyOn(document, "removeEventListener"); | ||
const el = document.createElement("div"); | ||
@@ -83,3 +79,3 @@ document.body.appendChild(el); | ||
const wrapper = createWrapper(() => { | ||
active = useOutsideClick(elRef, jest.fn()); | ||
active = useOutsideClick(elRef, vi.fn()); | ||
active.value = true; | ||
@@ -96,4 +92,4 @@ }); | ||
it("should remove listeners on unmount", async () => { | ||
const windowSpy = jest.spyOn(window, "removeEventListener"); | ||
const documentSpy = jest.spyOn(document, "removeEventListener"); | ||
const windowSpy = vi.spyOn(window, "removeEventListener"); | ||
const documentSpy = vi.spyOn(document, "removeEventListener"); | ||
const el = document.createElement("div"); | ||
@@ -104,3 +100,3 @@ document.body.appendChild(el); | ||
const wrapper = createWrapper(() => { | ||
active = useOutsideClick(elRef, jest.fn()); | ||
active = useOutsideClick(elRef, vi.fn()); | ||
active.value = true; | ||
@@ -107,0 +103,0 @@ }); |
{ | ||
"name": "@featherds/composables", | ||
"version": "0.12.5", | ||
"version": "0.12.6", | ||
"publishConfig": { | ||
@@ -12,3 +12,3 @@ "access": "public" | ||
"dependencies": { | ||
"@featherds/utils": "^0.12.5", | ||
"@featherds/utils": "^0.12.6", | ||
"vue": "^3.1.0-0" | ||
@@ -20,3 +20,3 @@ }, | ||
], | ||
"gitHead": "902fb935f136f66098ff1f777f7ca1294854cd42" | ||
"gitHead": "efae40a88230bf71e4927f9e40604d095fb92d35" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69715
1995
Updated@featherds/utils@^0.12.6