thymeleaf / thymeleaf-testing

Thymeleaf testing infrastructure
Apache License 2.0
77 stars 26 forks source link

Wildcard/pattern matching on output #3

Open Kleeven81 opened 10 years ago

Kleeven81 commented 10 years ago

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')}"/>
xdhmoore commented 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?

xdhmoore commented 10 years ago

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.

danielfernandez commented 10 years ago

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

xdhmoore commented 10 years ago

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

danielfernandez commented 10 years ago

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

xdhmoore commented 10 years ago

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

xdhmoore commented 10 years ago

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?

danielfernandez commented 10 years ago

@xdhmoore correct.

ldittmar81 commented 9 years ago

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.