mico
mico

Reputation: 12748

How to test appended javascript on wicket ajaxBehavior on JUnit test?

I have a function that appends in onload() method some javascript to the AjaxRequestTarget.

I load it by

add(onload);

and onload is having code like

AjaxEventBehavior event = new AjaxEventBehavior("onload") {
        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            attachJavascriptBehavior(target);
        }
    };
    return event;

attachJavascriptBehavior adds some javascript as text to the target.

I want to test it with WicketTester.

So far I know I can make calls like:

tester.executeAjaxEvent("some:path", "onclick");

and maybe same will apply somehow for the onload, too. I found I can then call

tester.assertRenderedPage(MyWebPage.class);

to test if page is rendered after the event (event tackles some content size), but even if I in browser get errors in console, this tests goes surprisingly through. How to catch that console.log has reported javascript errors?

Source:

How to test AjaxEventBehavior("onClick") for Apache Wicket radio button?

Upvotes: 0

Views: 858

Answers (1)

Andrea Del Bene
Andrea Del Bene

Reputation: 2511

as general tip, you can access to the last response with

String responseTxt = tester.getLastResponse().getDocument();

then you can check what has been returned to client.

Upvotes: 3

Related Questions