Skip to content

Instantly share code, notes, and snippets.

@philihp
Created May 16, 2023 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philihp/3704586a680659f85f6252769b7abf16 to your computer and use it in GitHub Desktop.
Save philihp/3704586a680659f85f6252769b7abf16 to your computer and use it in GitHub Desktop.
export const append = (demo = '', file = '') => {
const params = new URLSearchParams({
...(file ? { file } : {}),
ctl: 1,
embed: 1,
})
return `/${demo}?${params}`
}
import { append } from './main.js'
import test from 'node:test'
import assert from 'node:assert/strict'
test('handles having both demo and file', () => {
const out = append('demo', 'file')
assert.strictEqual(out, '/demo?file=file&ctl=1&embed=1')
})
test('handles only demo', () => {
const out = append('demo', undefined)
assert.strictEqual(out, '/demo?ctl=1&embed=1')
})
test('handles only file', () => {
const out = append(undefined, 'file')
assert.strictEqual(out, '/?file=file&ctl=1&embed=1')
})
test('handles missing demo and file', () => {
const out = append(undefined, undefined)
assert.strictEqual(out, '/?ctl=1&embed=1')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment