diff --git a/strcalc/src/main/frontend/components/request.test.js b/strcalc/src/main/frontend/components/request.test.js index c8a06bc..5685d68 100644 --- a/strcalc/src/main/frontend/components/request.test.js +++ b/strcalc/src/main/frontend/components/request.test.js @@ -6,6 +6,7 @@ */ import { post, postForm, postOptions } from './request' import { afterEach, describe, expect, test, vi } from 'vitest' +import { resolvedUrl } from '../test/helpers' // @vitest-environment jsdom describe('Request', () => { @@ -70,7 +71,7 @@ describe('Request', () => { // causes form.action to become `#{document.location.origin}/fetch` in // every environment. const form = document.createElement('form') - const resolvedAction = `${document.location.origin}/fetch` + const resolvedAction = resolvedUrl('./fetch') const res = { foo: 'bar' } const fetchStub = setupFetchStub(JSON.stringify(res)) diff --git a/strcalc/src/main/frontend/test/helpers.js b/strcalc/src/main/frontend/test/helpers.js index 2c08ae3..b889c51 100644 --- a/strcalc/src/main/frontend/test/helpers.js +++ b/strcalc/src/main/frontend/test/helpers.js @@ -10,6 +10,15 @@ * @module test-helpers */ +/** + * Resolves URL path against the current document location + * @param {string} path - path to resolve + * @returns {string} - the result of resolving path against document.location + */ +export function resolvedUrl(path) { + return new URL(path, document.location.href).toString() +} + /** * Enables tests to load page URLs both in the browser and in Node using JSDom. */