Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"rollup": "^4.50.0",
"sass": "^1.92.0",
"svg-sprite": "^2.0.4",
"vitest": "^3.2.4"
"vitest": "^4.0.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ describe("alchemy-element-editor", () => {
beforeEach(() => {
editor = getComponent(html)
Alchemy = {
Spinner: vi.fn(() => {
return {
spin: vi.fn(),
stop: vi.fn()
}
Spinner: vi.fn(function () {
this.spin = vi.fn()
this.stop = vi.fn()
}),
growl: vi.fn(),
routes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import "alchemy_admin/components/link_buttons/link_button"
import { renderComponent } from "../component.helper"

beforeEach(() => {
Alchemy.LinkDialog = vi.fn(() => ({
open: vi.fn(() => Promise.resolve({ data: {} }))
}))
Alchemy.LinkDialog = vi.fn(function () {
this.open = vi.fn(() => Promise.resolve({ data: {} }))
})
})

describe("alchemy-link-button", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import "alchemy_admin/components/link_buttons/unlink_button"
import { renderComponent } from "../component.helper"

beforeEach(() => {
Alchemy.LinkDialog = vi.fn(() => ({ open: vi.fn() }))
Alchemy.LinkDialog = vi.fn(function () {
this.open = vi.fn()
})
})

describe("alchemy-unlink-button", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ describe("alchemy-file-upload", () => {
describe("with image file", () => {
beforeEach(() => {
// mock file reader to response with an (invalid) image
vi.spyOn(global, "FileReader").mockImplementation(() => ({
readAsDataURL: vi.fn(),
addEventListener: (_load, callback) => callback(), // run the load callback
result: "data:image/png;base64,undefined"
}))
vi.spyOn(global, "FileReader").mockImplementation(function () {
this.readAsDataURL = vi.fn()
this.addEventListener = (_load, callback) => callback() // run the load callback
this.result = "data:image/png;base64,undefined"
})

renderComponent(
new File(["a".repeat(100)], "foo.png", { type: "image/png" })
Expand Down
32 changes: 17 additions & 15 deletions spec/javascript/alchemy_admin/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ globalThis.fetch = vi.fn().mockResolvedValue({
})

// Mock XMLHttpRequest to avoid network requests
globalThis.XMLHttpRequest = vi.fn(() => ({
open: vi.fn(),
send: vi.fn(),
setRequestHeader: vi.fn(),
abort: vi.fn(),
status: 200,
readyState: 4,
responseText: "",
response: "",
upload: {
globalThis.XMLHttpRequest = vi.fn(function () {
this.open = vi.fn()
this.send = vi.fn()
this.setRequestHeader = vi.fn()
this.abort = vi.fn()
this.status = 200
this.readyState = 4
this.responseText = ""
this.response = ""
this.upload = {
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
onprogress: vi.fn()
},
addEventListener: vi.fn(),
removeEventListener: vi.fn()
}))
}
this.addEventListener = vi.fn()
this.removeEventListener = vi.fn()
})

// Mock matchMedia for components that use it
Object.defineProperty(window, "matchMedia", {
Expand All @@ -106,7 +106,9 @@ globalThis.Alchemy = {
locale: "en",
growl: vi.fn(),
routes: {},
LinkDialog: vi.fn(() => ({ open: vi.fn() })),
LinkDialog: vi.fn(function () {
this.open = vi.fn()
}),
currentDialog: vi.fn(),
uploader_defaults: {},
PreviewWindow: {
Expand Down
Loading