#261 Testing JavaScript with Jasmine (revised)
The jasminerice gem makes it easy to test your JavaScript with Jasmine in a Rails application. Here I also cover jasmine-jquery and guard-jasmine.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
I like to wrap my classes on a global namespace such as:
And then:
Looks like a good idea, I'll use it in my future projects!
Nice episode!
I have issues trying to test blocking input into a text field. I made a jQuery plugin that forbids inputing number, spaces, or chars, but since triggering keypress, keyup or keydown dont actually print the value into the text field (it trigger the event but does not puts a value there) i have no way of making the correct expectation (not even with the sendkeys plugin).
Anyone knows how to test this kind of things?
Regarding the difference between
and
seems to be local only, that is, that the implicit declaration will not expose Mine in the local scope, which might be a pitfall
at first.
You can refer to it as @Mine in the local scope.
Ryan,
So am I right in thinking that I have to invoke the methods that would otherwise have been called on page load? That is, we cannot rely upon DOM events firing for our fixtures? Integration testing is where you would want to test that (or call the function manually in the Jasmine test)?
If your fixture form's input had the same id (#order_card_number) then you could include order.js.coffee in the spec. But this is probably a bad idea as the tests lose isolation and it's not really a substitute for a full acceptance test with capybara/selenium.
Anyone know the key differences between jasminerice and evergreen?
I am the author of jasminerice ( bias warning ). I just read of the evergreen docs. The difference seems to be that jasminerice is integrated for Ruby on Rails. If you are already using rails then jasminerice is probably what you want. If you are using javascript with something else or distributing javascript packages standalone then perhaps evergreen is for you.
If you don't use notification services like growl, put 'notification :off' at top of your Guardfile, and you won't see that notice when tests start up.
Thanks Ryan, I was wondering if you guys know why I keep getting a: "CreditCard is not defined" error? Even after following your tutorial word for word.
http://stackoverflow.com/questions/11396650/why-does-jasmine-ruby-not-find-my-js-class
Thanks for the tutorial Ryan. Has something changed with the Asset Pipeline in Rails 4 beta that I'm not aware of? After following your screencast, when I visit
http://localhost:3000/jasmine
, none of my assets are being loaded. The JavaScript and CSS tags are referencing things likehttp://localhost:3000/jasmine/assets/jasmine.js?body=1
instead ofhttp://localhost:3000/assets/jasmine.js?body=1
Do you have any ideas? I've been reading through the source of both Jasminerice and Rails and can't seem to figure this out. Thanks!Jasmine can have problems if you have a catchall route at the end of your routes.rb file. To solve, you can add
before the catchall in routes.rb
Cheers for that, twler.
Hello!
Does anybody know if Travis CI will run this type of tests? Having a lot of trouble finding info. on that particular subject.
fyi I just installed teaspoon, a new javascript runner for rails apps, looks really nice https://github.com/modeset/teaspoon Support asset pipeline, coffeescript, headless, and more.
Thanks for adding this… really nice
Hi Jose,
I cannot precisely answer your question regarding Travis CI. However you can find an article which covers the setup of TeamCity CI for automated headless testing of Javascript code - both Jasmine and CasperJS - in detail here:
http://www.jrubyonrails.de/2013/03/continuous-integration-for-jasmine--and-casperjs-tests.html
It might be a good starting point.
Pssst: sed 's/speces/spaces/g'
FYI - JasmineRice repo 2013/1/17 states:
Dell Phone Number is a toll-free number offered by dell technicians. Call anytime on +1-855-676-2448 (USA, CANADA).