-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
51 lines (40 loc) · 1.44 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import assert from 'node:assert/strict'
import test from 'node:test'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {find} from 'unist-util-find'
test('find', async function (t) {
const tree = fromMarkdown('Some _emphasis_, **strongness**, and `code`.')
assert(tree.type === 'root')
const paragraph = tree.children[0]
assert(paragraph.type === 'paragraph')
await t.test('should fail without tree', function () {
assert.throws(function () {
// @ts-expect-error: check that an error is thrown at runtime.
find()
})
})
await t.test('should fail without condition', function () {
assert.throws(function () {
// @ts-expect-error: check that an error is thrown at runtime.
find(tree)
})
})
await t.test('should find with string condition', function () {
const result = find(tree, 'value')
assert.equal(result, paragraph.children[0])
})
await t.test('should find with object condition', function () {
const result = find(tree, {type: 'emphasis'})
assert.equal(result, paragraph.children[1])
})
await t.test('should find with function condition', function () {
const result = find(tree, function (node) {
return node.type === 'inlineCode'
})
assert.equal(result, paragraph.children[5])
})
await t.test('should return undefined if no matches', function () {
const result = find(tree, 'nope, nope, nope')
assert.equal(result, undefined)
})
})