@@ -4,25 +4,33 @@ import GitHubSlugger from 'github-slugger';
4
4
import { VFile } from 'vfile' ;
5
5
6
6
import createMetadata from '../metadata.mjs' ;
7
+ import { u } from 'unist-builder' ;
7
8
8
9
describe ( 'createMetadata' , ( ) => {
9
10
it ( 'should set the heading correctly' , ( ) => {
10
11
const slugger = new GitHubSlugger ( ) ;
11
12
const metadata = createMetadata ( slugger ) ;
12
- const heading = {
13
- text : 'Test Heading' ,
14
- type : 'test' ,
15
- name : 'test' ,
16
- depth : 1 ,
17
- } ;
13
+ const heading = u ( 'heading' , {
14
+ type : 'heading' ,
15
+ data : {
16
+ text : 'Test Heading' ,
17
+ type : 'test' ,
18
+ name : 'test' ,
19
+ depth : 1 ,
20
+ } ,
21
+ } ) ;
18
22
metadata . setHeading ( heading ) ;
19
- strictEqual ( metadata . create ( new VFile ( ) , { } ) . heading , heading ) ;
23
+ strictEqual ( metadata . create ( new VFile ( ) , { } ) . heading . data , heading . data ) ;
20
24
} ) ;
21
25
22
26
it ( 'should set the stability correctly' , ( ) => {
23
27
const slugger = new GitHubSlugger ( ) ;
24
28
const metadata = createMetadata ( slugger ) ;
25
- const stability = 2 ;
29
+ const stability = {
30
+ type : 'root' ,
31
+ data : { index : 2 , description : '' } ,
32
+ children : [ ] ,
33
+ } ;
26
34
metadata . addStability ( stability ) ;
27
35
const actual = metadata . create ( new VFile ( ) , { } ) . stability ;
28
36
delete actual . toJSON ;
@@ -38,19 +46,26 @@ describe('createMetadata', () => {
38
46
const apiDoc = new VFile ( { path : 'test.md' } ) ;
39
47
const section = { type : 'root' , children : [ ] } ;
40
48
const heading = {
41
- text : 'Test Heading' ,
42
- type : 'test' ,
43
- name : 'test' ,
44
- depth : 1 ,
49
+ type : 'heading' ,
50
+ data : {
51
+ text : 'Test Heading' ,
52
+ type : 'test' ,
53
+ name : 'test' ,
54
+ depth : 1 ,
55
+ } ,
56
+ } ;
57
+ const stability = {
58
+ type : 'root' ,
59
+ data : { index : 2 , description : '' } ,
60
+ children : [ ] ,
45
61
} ;
46
- const stability = 2 ;
47
62
const properties = { source_link : 'test.com' } ;
48
63
metadata . setHeading ( heading ) ;
49
64
metadata . addStability ( stability ) ;
50
65
metadata . updateProperties ( properties ) ;
51
66
const expected = {
52
67
api : 'test' ,
53
- slug : 'test.html#test -heading' ,
68
+ slug : 'test-heading' ,
54
69
sourceLink : 'test.com' ,
55
70
updates : [ ] ,
56
71
changes : [ ] ,
@@ -61,6 +76,7 @@ describe('createMetadata', () => {
61
76
} ;
62
77
const actual = metadata . create ( apiDoc , section ) ;
63
78
delete actual . stability . toJSON ;
79
+ delete actual . heading . toJSON ;
64
80
deepStrictEqual ( actual , expected ) ;
65
81
} ) ;
66
82
} ) ;
0 commit comments