Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resolvedUrl() helper, apply to form action #54

Merged
merged 1 commit into from
Dec 17, 2023
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
3 changes: 2 additions & 1 deletion strcalc/src/main/frontend/components/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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))

Expand Down
9 changes: 9 additions & 0 deletions strcalc/src/main/frontend/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down