mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

IllegalStateException when calling push() in Manual PushMode #80

Closed hfazai closed 2 years ago

hfazai commented 2 years ago

With the manual mode, we should call push() explicitly to push the pending changes of the UI.

In my test it throws this exception:

Caused by: java.lang.IllegalStateException: Push not enabled
    at com.vaadin.flow.component.UI.push(UI.java:666)
    at org.kopi.galite.ui.vaadin.visual.VApplication$onAttach$1$1.execute(VApplication.kt:118)
    at com.vaadin.flow.component.UI.accessSynchronously(UI.java:444)
    at com.vaadin.flow.component.UI.access$000(UI.java:95)
    at com.vaadin.flow.component.UI$2.execute(UI.java:519)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.vaadin.flow.server.VaadinService.runPendingAccessTasks(VaadinService.java:2021)
    ... 65 more

It looks like MockedUI didn't set the push mode during setup. it's always = PushMode.DISABLED

So, I could workaround it with setting manually the push mode after setup

MockVaadin.setup(routes)
UI.getCurrent().pushConfiguration.pushMode = PushMode.MANUAL

If this is the best way to do it, maybe we can add it to the Karibu-Testing doc in the Async updates section?

mvysny commented 2 years ago

I tested a bit and there seem to be no harm in doing UI.getCurrent().pushConfiguration.pushMode = PushMode.AUTOMATIC by default. Therefore, that's what Karibu-Testing will do, starting from 1.3.1. However, if this change breaks something, just let me know and I'll revert the code and mention this in the docs.

Fixed in Karibu-Testing 1.3.1.