Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

standalone Jasmine vs Karma - Jasmine

I'm new to testing in general, and have been teaching myself Jasmine. I'm trying to understand the differences between running Jasmine and jQuery-Jasmine in Karma vs running Jasmine by itself. The tutorials for Jasmine don't address the adjustments that are needed if using Karma.

Can someone explain to me how Karma-Jasmine differs in requirements from the standalone Jasmine? Does it still require a spec runner, and is the file structure still the same?

I'm testing DOM events - a lot of click handlers - and don't understand how to mock this. Can someone outline some basic ideas? If I want to, for example, check that a p element has been added to a div after a user clicks a button, how would that work in both file structure and functions?

Thanks.

like image 450
fstopzero Avatar asked Oct 16 '14 18:10

fstopzero


1 Answers

Karma and Jasmine's SpecRunner.html are both test runners (aka spec runners). The difference between the two is that Karma is an application that runs outside the browser, while SpecRunner is a normal HTML file with a bunch of script references that you open up in a browser.

A test runner that lives outside the browser gives you a number of benefits:

  • automatically run tests in one or multiple browsers at once
  • automatically run tests on file changes, without having to manually refresh the browser
  • file pre-processing, i.e.
    • compiling TypeScript to JavaScript before running tests
    • inlining HTML templates into JavaScript
  • file/report generation, i.e. test coverage reports
  • test framework flexibility
  • easily include/exclude test and source files using file and folder patterns rather than trying to wrangle 100s of <script> references in a HTML file
like image 119
user2943490 Avatar answered Sep 20 '22 14:09

user2943490