Open Kleeven81 opened 10 years ago
+1 So, I haven't actually used thymeleaf-testing, but it seems like without this, the tests will always be brittle. As soon as someone changes the DOM structure or adds a CSS class, things will break. It would be nice to be able to do XPath or CSS style selectors to be able to assert only specific things about the results. Is there any way to hook into or override the matching currently, even just to be able to do some basic Regex matches?
Since I'm complaining, I also wanted to add that I've enjoyed using Thymeleaf. I really like how abstracted out things are and how many extension points there are.
@xdhmoore that's not complaining, that's actually adding valuable feedback :-)
Note that, even if pattern matching is not yet available, you can actually test only fragments of templates by providing a %FRAGMENT
directive. This directive allows you to use the same syntax as Thymeleaf's DOM selectors.
Thanks. Do they work after the template is rendered? I was having trouble understanding the difference between %FRAGMENT
and %INCLUDE
.
%FRAGMENT
actually works before the template is rendered. It selects a specific part of the template being executed and only executes that part.
%INCLUDE
... does not exist :-)
Lol, I guess I meant %INPUT
. Okay, I think I understand now. Thanks!
From what I can tell, %FRAGMENT
limits you to selecting elements, not attributes. So, you're still limited to strict matching (apart from whitespace) on elements. Is that correct?
@xdhmoore correct.
I have somethink like: <test:element .../> and when there is no id attribute, I generate a randomized id. Wildcard/pattern matching would be very nice.
In order to make more robust test for templates that have a variable output, for instance showing the current date, it would be nice to have either wildcard or pattern matching support in the output of test cases.
For example the following template would otherwise be impossible to test: