@@ -4,25 +4,33 @@ import GitHubSlugger from 'github-slugger';
44import { VFile } from 'vfile' ;
55
66import createMetadata from '../metadata.mjs' ;
7+ import { u } from 'unist-builder' ;
78
89describe ( 'createMetadata' , ( ) => {
910 it ( 'should set the heading correctly' , ( ) => {
1011 const slugger = new GitHubSlugger ( ) ;
1112 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+ } ) ;
1822 metadata . setHeading ( heading ) ;
19- strictEqual ( metadata . create ( new VFile ( ) , { } ) . heading , heading ) ;
23+ strictEqual ( metadata . create ( new VFile ( ) , { } ) . heading . data , heading . data ) ;
2024 } ) ;
2125
2226 it ( 'should set the stability correctly' , ( ) => {
2327 const slugger = new GitHubSlugger ( ) ;
2428 const metadata = createMetadata ( slugger ) ;
25- const stability = 2 ;
29+ const stability = {
30+ type : 'root' ,
31+ data : { index : 2 , description : '' } ,
32+ children : [ ] ,
33+ } ;
2634 metadata . addStability ( stability ) ;
2735 const actual = metadata . create ( new VFile ( ) , { } ) . stability ;
2836 delete actual . toJSON ;
@@ -38,19 +46,26 @@ describe('createMetadata', () => {
3846 const apiDoc = new VFile ( { path : 'test.md' } ) ;
3947 const section = { type : 'root' , children : [ ] } ;
4048 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 : [ ] ,
4561 } ;
46- const stability = 2 ;
4762 const properties = { source_link : 'test.com' } ;
4863 metadata . setHeading ( heading ) ;
4964 metadata . addStability ( stability ) ;
5065 metadata . updateProperties ( properties ) ;
5166 const expected = {
5267 api : 'test' ,
53- slug : 'test.html#test -heading' ,
68+ slug : 'test-heading' ,
5469 sourceLink : 'test.com' ,
5570 updates : [ ] ,
5671 changes : [ ] ,
@@ -61,6 +76,7 @@ describe('createMetadata', () => {
6176 } ;
6277 const actual = metadata . create ( apiDoc , section ) ;
6378 delete actual . stability . toJSON ;
79+ delete actual . heading . toJSON ;
6480 deepStrictEqual ( actual , expected ) ;
6581 } ) ;
6682} ) ;
0 commit comments