Skip to content

Commit

Permalink
Use jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Feb 17, 2024
1 parent 9967c98 commit f29851b
Show file tree
Hide file tree
Showing 3 changed files with 8,139 additions and 4,188 deletions.
20 changes: 12 additions & 8 deletions lib/url.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import assert from 'assert'
/* eslint-env jest */

import { parseInternalLinks } from './url.js'

const testCases = [
const cases = [
['https://stacker.news/items/123', '#123'],
['https://stacker.news/items/123/related', '#123/related'],
// invalid links should not be parsed so user can spot error
Expand All @@ -16,9 +17,12 @@ const testCases = [
['https://stacker.news/items/123?commentId=456&parentId=789', '#456']
]

for (const [href, expected] of testCases) {
const actual = parseInternalLinks(href)
if (actual !== expected) {
assert(false, `${href} - expected: ${expected} got: ${actual}`)
}
}
describe('internal links', () => {
test.each(cases)(
'parses %p as %p',
(href, expected) => {
const actual = parseInternalLinks(href)
expect(actual).toBe(expected)
}
)
})
Loading

0 comments on commit f29851b

Please sign in to comment.