-
Notifications
You must be signed in to change notification settings - Fork 226
/
index.test.js
37 lines (34 loc) · 1.3 KB
/
index.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
const metalsmith = require('metalsmith')
const plugin = require('./index.js')
describe('extract-page-headings plugin', () => {
let pages
beforeAll((done) => {
metalsmith('lib/extract-page-headings/fixtures')
.use(plugin())
.build((err, files) => {
if (err) {
return done(err)
}
pages = files
done()
})
})
it('generated heading metadata matches expected', () => {
const metadataHeadings = pages['example.md.njk'].headings
const expectedHeadings = [
{ aliases: null, depth: 1, text: 'Heading level 1', url: 'heading-level-1' },
{ aliases: null, depth: 2, text: 'Heading level 2', url: 'heading-level-2' },
{ aliases: null, depth: 3, text: 'Heading level 3', url: 'heading-level-3' }
]
expect(metadataHeadings).toEqual(expectedHeadings)
})
it('generates headings with aliases', () => {
const metadataHeadings = pages['example-with-aliases.md.njk'].headings
const expectedHeadings = [
{ aliases: 'one', depth: 1, text: 'Heading level 1', url: 'heading-level-1' },
{ aliases: 'two', depth: 2, text: 'Heading level 2', url: 'heading-level-2' },
{ aliases: 'three', depth: 3, text: 'Heading level 3', url: 'heading-level-3' }
]
expect(metadataHeadings).toEqual(expectedHeadings)
})
})