-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathexample-has-heading.js
More file actions
29 lines (26 loc) · 941 Bytes
/
example-has-heading.js
File metadata and controls
29 lines (26 loc) · 941 Bytes
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
const describeRule = require('../../test-utils/describe-rule')
const getMarkdownAstNodesOfType = require('../../utils/get-markdown-ast-nodes-of-type')
describeRule('testcase has heading', ({ filename, markdownAST }) => {
/**
* get all headings of example examples (eg: #### Failed Example 1)
*/
const testcaseHeadings = getMarkdownAstNodesOfType(markdownAST, 'heading')
.filter(({ depth, children }) => {
return depth === 4 && children && children.length > 0
})
.map(({ children }) => {
const [textNode] = children
return textNode.value
})
/**
* get code blocks in markdown body
*/
const testcaseCodeSnippets = getMarkdownAstNodesOfType(markdownAST, 'code')
/**
* Check if filename has `id` as a part of the name
*/
test('each testcase has a heading', () => {
const msg = `Not all examples have headings in ${filename}.`
expect(testcaseHeadings.length, msg).toBe(testcaseCodeSnippets.length)
})
})