Skip to content

Commit e1538a4

Browse files
authored
Merge pull request #1780 from romainmenke/add-test-for-sorting-nodes--courageous-malayan-civet-f154d4f2bc
add test for sorting container.nodes
2 parents c047e0a + 24c1432 commit e1538a4

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/container.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,4 +814,31 @@ test('allows to clone nodes', () => {
814814
is(root2.toString(), 'a { color: black; z-index: 1 } b {}')
815815
})
816816

817+
test('container.nodes can be sorted', () => {
818+
let root = parse('@b; @c; @a;')
819+
let b = root.nodes[0];
820+
821+
root.nodes.sort((x, y) => {
822+
return (x as AtRule).name.localeCompare((y as AtRule).name)
823+
})
824+
825+
// Sorted nodes are reflected in "toString".
826+
is(root.toString(), ' @a;@b; @c;')
827+
828+
// Sorted nodes are reflected in "walk".
829+
let result: string[] = [];
830+
root.walkAtRules((atRule) => {
831+
result.push(atRule.name.trim())
832+
});
833+
834+
is(result.join(' '), 'a b c')
835+
836+
// Sorted nodes have the corect "index".
837+
is(root.index(b), 1)
838+
839+
// Inserting after a sorted node results in the correct order.
840+
b.after('@d;');
841+
is(root.toString(), ' @a;@b;@d; @c;')
842+
})
843+
817844
test.run()

0 commit comments

Comments
 (0)