Jingo and qUnit

5 views
Skip to first unread message

Adam Mills

unread,
Feb 13, 2012, 2:41:54 PM2/13/12
to jingo...@googlegroups.com
Hi,

I have started playing with Jingo and love it!
I'm starting to integrate it into my current project and was wondering about the best way to bring in modules to qUnit tests?
Is there any other way to load modules into the current context or do people just wrap each test in  jingo.annonymous()?

Thanks
Adam




Sean Duncan

unread,
Feb 13, 2012, 3:07:26 PM2/13/12
to Jingo Users
Adam,

Jingo actually uses jqUnit and jqMock for its own test suite. As I
recall jqUnit and qUnit are pretty closely related so I think the
source for the Jingo test suite might actually answer your question
fairly well.
Here is the link to the source on google code:
http://code.google.com/p/jingo/source/browse/#svn%2Fcore%2Ftrunk%2Fsrc%2Ftest%2Fjavascript.
If you still have questions please reply and I'll see what I else I
can dig up.

As an aside I have to say that It pains me a little to see that
Jingo's source is maintained in SVN. If I had it to do over again or
had the time to move it I much rather see the whole project on GitHub.

HTH,

-Sean

Adam Mills

unread,
Feb 13, 2012, 3:13:06 PM2/13/12
to jingo...@googlegroups.com
Jingo for the most part can just reference it's js file and get direct access to objects as they aren't in jingo modules.
The few tests for loading modules do wrap the test body in jingo.annonymous

I was hoping to be able todo something like jingo.load('my.namespace'); in the tests before() method
as retro-fitting each individual test will be a pain.

I'll keep digging into jingo and see if i can find how to load a module by brute force :)

Sean Duncan

unread,
Feb 13, 2012, 3:35:00 PM2/13/12
to Jingo Users
Adam,

I realized the error of my ways shortly after I hit 'send'. Jingo, by
design, is tiny and avoids having external dependencies so I doesn't
really have to eat much of its own dog food in its test suite.

I can say that when I've used Jingo in projects that my tests tend to
be written as jingo modules themselves. A test ends up being a module
with requires for the module under test as well as any slick test
helper modules that I may have written. It is also usually a pretty
trivial (yet totally optional) exercise to "jingoize" third party
libraries such as jquery or jqunit. Many of these libs come wrapped
in an anonymous function to ensure they have a local scope. This
anonymous function is usually a great candidate to become the module
body callback if you want to wrap the third party library in a jingo
module envelope. I totally understand your reluctance to converting
all of your existing tests to jingo modules. However, if you are
enjoying the impact Jingo has on your production code I think you'll
find there are similar benefits to having it manage your test
dependencies also.

Take care,

-Sean

Adam Mills

unread,
Feb 13, 2012, 3:44:27 PM2/13/12
to jingo...@googlegroups.com
I am looking for a way to essentially jingo-ize a test module (or test fixture if you will)
I am using specit on top of qunit, so i'd like to see each "describe" get jingo-ized

Doing it for each test method on a fixture ("it" in specit) seems like overkill.

Sean Duncan

unread,
Feb 13, 2012, 3:57:13 PM2/13/12
to Jingo Users
I'm not familiar with specit. From your description it sounds quite a
bit like RSpec for Ruby. I agree that a jingo module, anonymous or
otherwise, for each "example" seems like overkill particularly if you
are shooting for the "one assertion per test" approach. I was
referring to each test file being a Jingo module, but without being
more familiar with specit I can't be sure whether that would be enough
to accomplish what you are after. Once you get things figured out it
would be awesome if you'd post a code example.

Adam Mills

unread,
Feb 14, 2012, 7:19:53 AM2/14/12
to jingo...@googlegroups.com
Im a little new to the JS world, so i wasn't really seeing it. It was very easy to wrap it in jingo.
With a little more work, im sure you could overload the describe method to just take the requires parameters
SpecIt is RSpec Style syntax for JS

$(function() {
    jingo.anonymous({
        require: ['hallmart.Greeter'],
        exec: function() {

            describe("Qunit.Jingo", function() {


                before(function() {

                });

                after(function() {
                });


                it("Should Log Hello", function() {

                    new hallmart.Greeter().welcome("adam");
                    ok(true);

                });

            });
        }
    });
});

Reply all
Reply to author
Forward
0 new messages