Error node locations may vary across time but one might still want to have a test to express that an error is expected.
This can be achieved using the :error attribute feature of tree-sitter that was introduced in version 0.22.0 of the tree-sitter CLI tool.
Below is a sample test.
================================================================================
Invalid comment
:error
:language(xml)
================================================================================
<error>
<!-- invalid -- -->
</error>
--------------------------------------------------------------------------------
There are more examples here.