Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for sorting container.nodes #1780

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/container.test.ts
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()