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

Wildcard/pattern matching on output #3

Open
Kleeven81 opened this issue Dec 9, 2013 · 9 comments
Open

Wildcard/pattern matching on output #3

Kleeven81 opened this issue Dec 9, 2013 · 9 comments

Comments

@Kleeven81
Copy link

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
Copy link

xdhmoore commented Jun 3, 2014

+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
Copy link

xdhmoore commented Jun 3, 2014

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
Copy link
Member

@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
Copy link

xdhmoore commented Jun 3, 2014

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

@danielfernandez
Copy link
Member

%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
Copy link

xdhmoore commented Jun 3, 2014

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

@xdhmoore
Copy link

xdhmoore commented Jun 3, 2014

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
Copy link
Member

@xdhmoore correct.

@ldittmar81
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants