Skip to content

Instantly share code, notes, and snippets.

@stujo
Created October 17, 2014 17:18
Show Gist options
  • Save stujo/54e1245581428b51e32c to your computer and use it in GitHub Desktop.
Save stujo/54e1245581428b51e32c to your computer and use it in GitHub Desktop.
Jasmine

#Due Monday

P 5-9 Due Monday along with P10 MVP Outline as Issue On Challenge P10 Presented on Friday

P7 Reviews

#Jasmine - Unit Testing for JavaScript

#Headline

  • Demonstrate Jasmine for testing JavaScript

#Overview

  • Jasmine for Simple MVC
  • Considerations for Testing Components
  • Using Spies (a.k.a. mocks, doubles)
  • Optional: Using Karma (Testacular) to run JavaScript Unit Tests

#Jasmine for Simple MVC

  • Unit testing Model
  • cat_simple_mvc/test/spec/CatModelSpec.js
    • beforeEach
    • it
    • describe

#Considerations for Testing Components

  • Loose binding
  • Pass in Objects to your constructors / factories

#Using Spies (a.k.a. mocks, doubles)

  • Some object rely on other
  • Unit testing Controller
  • cat_simple_mvc/test/spec/CatControllerSpec.js

#Review

  • Jasmine for Simple MVC
  • Considerations for Testing Components
  • Using Spies (a.k.a. mocks, doubles)

#Optional Bonus

  • Leave if you want
  • Karma node based javascript test running

#Using Karma to run JavaScript Unit Tests

  • From the angular team
  • Used to be called Testacular renamed for unknown reason
  • karma start
  • Launches browser
  • Watches Filesystem
  • Runs tests on changes
    • ddescribe - run single suite
    • iit - run single test
    • console.log('xyz');
    • debugger;
  • Multi Browser Support
  • Code Coverage? - Go Explore

##Installation

  • Requires node
$ node -v
# v0.10.29
$ brew install npm
$ cd my_project
$ npm install -g karma-cli
$ npm install -g phantomjs
$ npm install karma-jasmine@2_0 --save-dev
$ npm install karma-phantomjs-launcher --save-dev
$ karma init karma.conf.js
  • Use Chrome

  • Use PhantomJS instead

  • --browsers: ['Chrome'],--

  • browsers: ['PhantomJS'],

  • Coverage npm install karma-coverage --save-dev

  • Adding View Tests

  • Use karma-jasmine-jquery for fixtures

  • Requires jquery on tests :(

  • cat_simple_mvc/test/spec/CatViewSpec.js

#Resources

#More Links

@bluehawk27
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment