Poop Sheet

Jasmine

Installing

Download the latest zip file from Github.

unzip jasmine-standalone-6.2.0.zip
Archive:  jasmine-standalone-6.2.0.zip
  inflating: LICENSE                 
  inflating: SpecRunner.html         
  inflating: lib/jasmine-6.2.0/jasmine_favicon.png  
  inflating: lib/jasmine-6.2.0/jasmine.js  
  inflating: lib/jasmine-6.2.0/jasmine-html.js  
  inflating: lib/jasmine-6.2.0/jasmine.css  
  inflating: lib/jasmine-6.2.0/boot0.js  
  inflating: lib/jasmine-6.2.0/boot1.js  
  inflating: src/Song.js             
  inflating: src/Player.js           
  inflating: spec/SpecHelper.js      
  inflating: spec/PlayerSpec.js      

Alternatively:

git clone https://github.com/jasmine/jasmine.git

The key files are in jasmine/lib/jasmine-core.

Home Page

The SpecRunner.html is a template for a file I copy to /project-home/test/index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner v6.2.0</title>

  <link rel="shortcut icon" type="image/png" href="lib/jasmine-6.2.0/jasmine_favicon.png">
  <link rel="stylesheet" href="lib/jasmine-6.2.0/jasmine.css">

  <script src="lib/jasmine-6.2.0/jasmine.js"></script>
  <script src="lib/jasmine-6.2.0/jasmine-html.js"></script>
  <script src="lib/jasmine-6.2.0/boot0.js"></script>
  <!-- optional: include a file here that configures the Jasmine env -->
  <script src="lib/jasmine-6.2.0/boot1.js"></script>

  <!-- include source files here... -->
  <script src="src/Player.js"></script>
  <script src="src/Song.js"></script>

  <!-- include spec files here... -->
  <script src="spec/SpecHelper.js"></script>
  <script src="spec/PlayerSpec.js"></script>

</head>

<body>
</body>
</html>

Hacking modules

Initially I loaded my Jasmine spec files as modules and imported my JavasScript modules into that.

Subsequently, I’ve found commenting out import and export statements during the early phases of test-driven development simplified things. So the “modules under development” are simply normal Javascript files loaded leaves first, then clients that depend on them, and finally the spec file:

  <script src="deck.js"></script>
  <script src="card.js"></script>
  <script src="game.js"></script>
  <script src="spec.js"></script>

The advantage is auxiliary functions local to a module are seen by the spec file to be tested.

Later the JavaScript modules can be copied to their production position and their import and export lines uncommented.

Behaviour Driven Development Jargon

Given When Then

G i v e n W h e n T h e n

Design by Contract

Client must ensure precondition.

Supplier may assume precondition.

R e q u i r e D o E n s u r e

Arrange Act Assert

A r r a n g e A c t A s s e r t