GWT unit tests along with JsInterop and external javascript

243 views
Skip to first unread message

ateletin

unread,
May 3, 2016, 6:57:44 AM5/3/16
to google-we...@googlegroups.com
My test case is simple, but it's not working.
I have an external .js file containing an object, Person, which has 2
fields, firstName and lastName, and a method, getFullName. It also have a
constructor that initialize those 2 fields.

I have created a java object Person which is annotated with
@JsInterop(isNative=true, namespace="...", name=Person).

My test case is to create a person and to ask for its full name:
Person pilot = new Person("Kimi", "Raikkonen");
assertTrue(person.getFullName().equals("Kimi Raikkonen"));

The problem is that the Person pilot is not initialized correctly and the
method getFullName() couldn't be found. Neither the fields doesn't exist in
pilot object..

Note that this happens ONLY at GWT Unit Test running, and NOT when I run my
application normally; at normal running, it works as expected.

Have someone did unit test for gwt using jsinterop and external js? Is there
something that I've missed?

Thank you.



--
View this message in context: http://google-web-toolkit.2317884.n4.nabble.com/GWT-unit-tests-along-with-JsInterop-and-external-javascript-tp15739.html
Sent from the Google Web Toolkit mailing list archive at Nabble.com.

salk31

unread,
May 4, 2016, 4:58:30 AM5/4/16
to GWT Users, alin.t...@bearingpoint.com
I've done jsinterop. With the maven plugin have you set <jsInteropMode>JS</jsInteropMode> ?

Your use case takes me back! Twenty years ago I did an F1 website in Italian ;) 

ateletin

unread,
May 4, 2016, 6:14:06 AM5/4/16
to google-we...@googlegroups.com
Yes, I have put <jsInteropMode>JS</jsInteropMode> although I don't think it
is really necessary because running the app (not the unit tests) works ok
without this flag. Anyway, I have it.
The error I got when I want to create a Person object in my unit test is:
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read
property "example" from undefined

The Persons' definitions from js and java are:
JS: Ext.define('com.example.formula.client.Person', {...});

JAVA: package com.example.formula.client;

@JsType(isNative = true, namespace="com.example.formula.client",
name="Person")
public class Person {
...
}

It seems that the namespace of the JsType is not working with GwtTestCase..
I don't know..



--
View this message in context: http://google-web-toolkit.2317884.n4.nabble.com/GWT-unit-tests-along-with-JsInterop-and-external-javascript-tp15739p15743.html

salk31

unread,
May 4, 2016, 6:24:20 AM5/4/16
to GWT Users, alin.t...@bearingpoint.com
Probably something else you have already done but you have put the test into production mode too via the maven plugin?

salk31

unread,
May 4, 2016, 6:50:18 AM5/4/16
to GWT Users, alin.t...@bearingpoint.com
Sorry if you have already said but what version of GWT and maven plugin are you using?

ateletin

unread,
May 4, 2016, 7:21:43 AM5/4/16
to google-we...@googlegroups.com
Yes, I run it in production mode.
I use GWT2.8.0-Beta1.



--
View this message in context: http://google-web-toolkit.2317884.n4.nabble.com/GWT-unit-tests-along-with-JsInterop-and-external-javascript-tp15739p15746.html

salk31

unread,
May 4, 2016, 7:31:17 AM5/4/16
to GWT Users, alin.t...@bearingpoint.com
Ah. Sorry, I've not used that yet so I'm probably telling you rubbish. Good luck.

Thomas Broyer

unread,
May 4, 2016, 9:19:53 AM5/4/16
to GWT Users, alin.t...@bearingpoint.com
How are you loading the JS script into the page? Keep in mind that GWTTestCase doesn't use your HTML host page; you have to use ScriptInjector in GWTTestCase.

biciusc...@gmail.com

unread,
May 9, 2016, 3:56:37 AM5/9/16
to GWT Users, alin.t...@bearingpoint.com
We successfully load JS scripts with ScriptInjector in GWTTestCase and test pass. Do you have any sugesstion on how to use the debug mode in this case? Because even if we start the test in debug, is not stopping to the breackpoint.

Thomas Broyer

unread,
May 9, 2016, 5:03:07 AM5/9/16
to GWT Users, alin.t...@bearingpoint.com


On Monday, May 9, 2016 at 9:56:37 AM UTC+2, biciusc...@gmail.com wrote:
We successfully load JS scripts with ScriptInjector in GWTTestCase and test pass. Do you have any sugesstion on how to use the debug mode in this case? Because even if we start the test in debug, is not stopping to the breackpoint.

I think you'd use the "manual" runstyle (see http://www.gwtproject.org/doc/latest/DevGuideTesting.html#Manual_Mode) and debug using your browser dev tools (like you debug your app).
Reply all
Reply to author
Forward
0 new messages