-
Notifications
You must be signed in to change notification settings - Fork 51
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
Events subsystem is not testable #9
Comments
Could you give some more details about what exactly you're trying to do and how you'd like it to work? It sounds like you want GwtMockito to return a real event bus when you call GWT.create(EventBus.class) instead of a mock. I'm not sure if it makes sense to special-case this in GwtMockito, but it should be possible to make this happen in your own tests by doing something like this: GwtMockito.useProviderForType(EventBus.class, new FakeProvider() {
public EventBus getFake(Class<?> type) {
return new SimpleEventBus();
}
}); This will cause GwtMockito to always return a SimpleEventBus from calls to GWT.create, which might do what you want. The technique I usually use for testing event-based applications is expose event handler methods and call them directly in my tests, rather than firing the event in the test and relying on the event bus to dispatch it. This technique works really well with EventBinder since it requires that you have explicit handler methods. |
The use case: new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
//... some code here
//if the new value and previous selection is not equal, fire the change event
if (fireEvent)
ValueChangeEvent.fire(CustomListBox.this, model);
}
}; where after some magic i am firing the ValueChangeEvent. Even if i can emulate DOM event with calling the handler directly from a test , i can't really catch the ValueChangeEvent event from the test to get the changed value. Also, as i can see in the HandlerManager (which is resposnsible for creating the event bus in the GWT Widget class) is created with a new operator, not with GWT.create(). Will this Fake thing work if the operator is new? |
Hello! I've tried to test some widget behavior , but failed since my code operating on GWT event and handler manager. Will you support testing of GWTEvents? As i see you are mocking the EventBus object, that's why the event doesn't intercepted by registered Handlers.
I've tried to perform events testing in the composite with EventBus created by hand and everything worked perfectly.
So far ensureHandlerMehtod should return the real bus and not the mock.
Thanks!
The text was updated successfully, but these errors were encountered: