Unit testing with a Javascript library: how to load it?

87 views
Skip to first unread message

Larry Clapp

unread,
Dec 27, 2015, 10:26:10 PM12/27/15
to GopherJS
I'm working on a skeleton Vue.js + GopherJS app.  Vue.js is a MVC library (technically an MVVM library) similar to AngularJS.  I'd like to write unit tests using Go.  (I could use Jasmine, but that's in JS, and I'd rather, if I possibly can, stick with Go; that's kind of the point of GopherJS, after all! :)

The Vue library I'm using (https://github.com/theclapp/js/blob/master/examples/vue/vue.go) expects the "Vue" JS global to already exist.  When run in a web page, I just load vue.js first, before my own code, and that works.

When running "gopherjs test", this doesn't work.  There's no web page, so there's no way to load "vue.js" before my own code.

Is there some way to do this that I'm missing, or is there a better/different way to do unit testing?  Should I abandon my hope of writing unit tests in Go and just use JS, Jasmine, and Karma?

Thanks!

-- Larry

Joop Kiefte

unread,
Jan 15, 2016, 4:46:11 AM1/15/16
to GopherJS
The tests run on node.js, and node.js has ways to import javascript. http://stackoverflow.com/questions/5797852/in-node-js-how-do-i-include-functions-from-my-other-files shows how that works in Javascript, you can just do the same thing in GopherJS in your testing package.

Op maandag 28 december 2015 04:26:10 UTC+1 schreef Larry Clapp:

Larry Clapp

unread,
Jan 15, 2016, 3:23:03 PM1/15/16
to GopherJS
Thanks!


On Friday, January 15, 2016 at 4:46:11 AM UTC-5, Joop Kiefte wrote:
The tests run on node.js, and node.js has ways to import javascript. http://stackoverflow.com/questions/5797852/in-node-js-how-do-i-include-functions-from-my-other-files shows how that works in Javascript, you can just do the same thing in GopherJS in your testing package.

Op maandag 28 december 2015 04:26:10 UTC+1 schreef Larry Clapp:
I'm working on a skeleton Vue.js + GopherJS app.  Vue.js is a MVC library (technically an MVVM library) similar to AngularJS.  I'd like to write unit tests using Go.  (I could use Jasmine, but that's in JS, and I'd rather, if I possibly can, stick with Go; that's kind of the point of GopherJS, after all! :)

[snip] 
Reply all
Reply to author
Forward
0 new messages