Skip to content

Commit

Permalink
Merge pull request #1780 from romainmenke/add-test-for-sorting-nodes-…
Browse files Browse the repository at this point in the history
…-courageous-malayan-civet-f154d4f2bc

add test for sorting container.nodes
  • Loading branch information
ai authored Sep 29, 2022
2 parents c047e0a + 24c1432 commit e1538a4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,31 @@ test('allows to clone nodes', () => {
is(root2.toString(), 'a { color: black; z-index: 1 } b {}')
})

test('container.nodes can be sorted', () => {
let root = parse('@b; @c; @a;')
let b = root.nodes[0];

root.nodes.sort((x, y) => {
return (x as AtRule).name.localeCompare((y as AtRule).name)
})

// Sorted nodes are reflected in "toString".
is(root.toString(), ' @a;@b; @c;')

// Sorted nodes are reflected in "walk".
let result: string[] = [];
root.walkAtRules((atRule) => {
result.push(atRule.name.trim())
});

is(result.join(' '), 'a b c')

// Sorted nodes have the corect "index".
is(root.index(b), 1)

// Inserting after a sorted node results in the correct order.
b.after('@d;');
is(root.toString(), ' @a;@b;@d; @c;')
})

test.run()

0 comments on commit e1538a4

Please sign in to comment.