I'm trying to test my Backbone.js web application.
Since this application is basically only consuming web services, there is not really business logic inside, and the app is simply addressing calls to our API.
I'd like to use Zombie.js for ma integration test suit, which works - for the moment - with Karma and Jasmine.
My problem is I'm using RequireJS, and because Zombie doesn't seem to be AMD compliant, I can't import Zombie into my test view.
Any ideas?
Can you include zombie js in your test runner? I think karma has a files array in its config
source: http://toon.io/how-to-setup-karma-javascript-test-runner/
Related
I am testing the javascript that's sitting on top of my Rails app (using sprockets) with NPM (which is not connected to my Rails app in any way).
Everything is working great - the tests run (using NPM).
But how do I tell MochaJS which JavaScript files I want to test in my Rails app?
After doing some research I found out one would need to use a task runner such as Gulp, Grunt, or Webpack along with MochaJS to watch the files being tested.
You may want to look into konacha gem which integrates mocha and chai in the rails workflow.
Konacha ... is a Rails engine that allows you to test your JavaScript with the Mocha test framework and chai assertion library.
It ... does not attempt to be framework agnostic. By sticking with Rails, Konacha can take full advantage of features such as the asset pipeline and engines.
It can be integrated with guard through guard-konacha to watch for files and re-run tests.
Until now, I've done all my testing with just Jasmine and jQuery to automate the browser. I am starting to explore Karma but it seems to be set up only for unit tests that involve loading HTML fragments as test fixtures and I find no way to load a whole web page. Am I missing something or is this simply the wrong tool for what I am trying to do?
From the karma FAQ's section:
Can I use Karma to do end to end testing?
Karma has primarily been designed for low level (unit) testing. If it's an AngularJS app, you can use Karma with the karma-ng-scenario plugin. However, we recommend Protractor for high-level testing.
Typically, loading a whole web page goes beyond the scope of single units of code: you need to spin up a browser, load the page and make your actions and assertions. End-to-end testing frameworks like Protractor, Nightwatch.js or Webdriver.io might be more suitable for this specific case.
You can do integration testing using the following toolchain:
Karma ➔ Mocha ➔ Mocha-CasperJS ➔ CasperJS.
Check out the mocha-casperjs package.
I have some Angular/Rails app where Rails part is just JSON API, all front works is doing by AngularJS. I've made model/controller test already using RSpec, and now I want to make some integration tests. Earlier I use request test (with Capybara, Selenium) of RSpec to test my pages/JS, but Angular is often tested by Karma/Jasmine, and I don't understand what way is preferred in Angular/Rails app. Please, give me advice, may be you share some experience with me. Thanks.
First of all you should test everything wisely. I will recommend great series of blog posts from the link below.
Since you are already familiar with RSpec, keep using it for your rails tests like models, controllers, request, etc.
For your Angularjs tests, karma and Jasmine are great choices. But Rails uses Sprockets for asset management so configuring karma can be a little bit tricky. For Rails and Jasmine I wrote a rake task. To run javascript tests you should simply run rake karma:start. I shared the link of the gist below.
The gist contains 2 files. You should put them:
karma.rake -> lib/tasks
karma.unit.js -> spec/javascripts/
Finally you should run feature/acceptance tests with Capybara.
Testing Series Intro
The Gist of Rake Task and Karma Configuration
I'm building my app using backbone and react inside of a rails app. I saw that all the recommended test packages (jest, jasmine, etc) are all node based. From what I know, I can get node on my rails project but I'd prefer not to.
Is there a way to test with something like jest without node? Or is there another package that isn't based on node that works with react.
Many test frameworks have browser based test runners, if you're willing to give up command line based testing then you can do this. Jasmine and Mocha both allow this.
Node.js is the de facto platform for web development tools (Ruby being the second most popular). Consider adopting the dependency, or you'll be fighting an uphill battle.
I am trying to choose a setup for testing a webapp that uses Backbone and RequireJS.
I will try to do most of my unit testing from javascript and I am in doubt whether it is better to load my whole app before calling the testing framework or to use RequireJS to dinamycally load just the modules that are being tested by each test.
As this site is just for Q&A and not open to discussion, I will reformulate: Do you have any strong argument against not loading the whole app upfront when unit testing?
The best way is to test each of your Models/Collections/Views separately in unit test. Starting the whole app in a unit test would it made really hard to test all cases for a module. As you mention requireJS you should also mock most of the dependencies of a module using squireJS.
But you should additionally have some integration tests where you test the behavior of the whole app in a headless browser using a tool like selenium, casperJS or capybara.
With requirejs, there are two ways for you to interpret loading upfront:
During development, where r.js is not be used, and just depend on configuration on requirejs.config
After r.js optimization, where the modules can be restructure by r.js configuration