thymeleaf-testing icon indicating copy to clipboard operation
thymeleaf-testing copied to clipboard

Wildcard/pattern matching on output

Open Kleeven81 opened this issue 11 years ago • 9 comments

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:

<element th:attr="data-end-date=${#calendars.format(#calendars.createNow(),'yyyy-MM-dd')}"/>

Kleeven81 avatar Dec 09 '13 07:12 Kleeven81

+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?

xdhmoore avatar Jun 03 '14 18:06 xdhmoore

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 avatar Jun 03 '14 19:06 xdhmoore

@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.

danielfernandez avatar Jun 03 '14 19:06 danielfernandez

Thanks. Do they work after the template is rendered? I was having trouble understanding the difference between %FRAGMENT and %INCLUDE.

xdhmoore avatar Jun 03 '14 19:06 xdhmoore

%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 :-)

danielfernandez avatar Jun 03 '14 19:06 danielfernandez

Lol, I guess I meant %INPUT. Okay, I think I understand now. Thanks!

xdhmoore avatar Jun 03 '14 19:06 xdhmoore

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 avatar Jun 03 '14 21:06 xdhmoore

@xdhmoore correct.

danielfernandez avatar Jun 03 '14 22:06 danielfernandez

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.

ldittmar81 avatar Feb 24 '15 10:02 ldittmar81