Skip to content

Commit 4d098c5

Browse files
authored
test: add tests for isNodeEmpty function (#574)
1 parent df9bc26 commit 4d098c5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/utils/nodes.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Schema} from 'prosemirror-model';
2+
3+
import {isNodeEmpty} from './nodes';
4+
5+
const schema = new Schema({
6+
nodes: {
7+
doc: {content: 'block+'},
8+
yfm_cut_content: {content: 'block+'},
9+
paragraph: {content: 'inline*', group: 'block'},
10+
text: {group: 'inline'},
11+
code_block: {content: 'inline*', group: 'block'},
12+
},
13+
});
14+
15+
describe('isNodeEmpty', () => {
16+
it('yfm_cut_content with an empty paragraph', () => {
17+
const emptyParagraph = schema.nodes.paragraph.create();
18+
const yfmCutContent = schema.nodes.yfm_cut_content.create(null, emptyParagraph);
19+
20+
expect(isNodeEmpty(yfmCutContent)).toBe(true);
21+
});
22+
23+
it('yfm_cut_content with a paragraph containing text', () => {
24+
const textNode = schema.text('Hello, world!');
25+
const paragraphWithText = schema.nodes.paragraph.create(null, textNode);
26+
const yfmCutContent = schema.nodes.yfm_cut_content.create(null, paragraphWithText);
27+
28+
expect(isNodeEmpty(yfmCutContent)).toBe(false);
29+
});
30+
31+
it('fm_cut_content with a non-paragraph block', () => {
32+
const codeBlock = schema.nodes.code_block.create();
33+
const yfmCutContent = schema.nodes.yfm_cut_content.create(null, codeBlock);
34+
35+
expect(isNodeEmpty(yfmCutContent)).toBe(false);
36+
});
37+
});

0 commit comments

Comments
 (0)