Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thought the same thing (regarding documentation) when I first tried to use jasmine-node. As it turns out, though, there's virtually nothing to set up--it works just like RSpec or other testing tools you might be used to. To use Jasmine with your Node project, do the following:</p> <ol> <li>Make sure <code>jasmine-node</code> is installed and that you can run its executable.</li> <li>Write your specs! I have a sample spec below these steps.</li> <li>Run your specs with the command <code>jasmine-node specs/</code> (where <code>specs/</code> points to the directory with your specs).</li> </ol> <p>That's it! You may find it beneficial to use some sort of build tool, like <code>cake</code> for CoffeeScript or <a href="https://github.com/mde/jake"><code>jake</code></a>.</p> <p>Here's a quick example of part of a spec from a small project I used jasmine-node on recently; apologies that it's in CoffeeScript. (As an aside: to run jasmine-node against CoffeeScript specs, pass it the <code>--coffee</code> option.)</p> <pre><code>Chess = require('../lib/chess') Board = Chess.Board jasmine = require('jasmine-node') describe "A chess board", -&gt; beforeEach -&gt; @board = new Board it "should convert a letter/number position into an array index", -&gt; expect(Board.squares["a1"]).toEqual(0) expect(Board.squares["b1"]).toEqual(1) expect(Board.squares["a2"]).toEqual(16) expect(Board.squares["h8"]).toEqual(119) it "should know if an array index represents a valid square", -&gt; expect(Board.is_valid_square 0).toBeTruthy() expect(Board.is_valid_square 7).toBeTruthy() expect(Board.is_valid_square 8).toBeFalsy() expect(Board.is_valid_square 15).toBeFalsy() expect(Board.is_valid_square 119).toBeTruthy() expect(Board.is_valid_square 120).toBeFalsy() expect(Board.is_valid_square 129).toBeFalsy() expect(Board.is_valid_square -1).toBeFalsy() it "should start off clear", -&gt; for i in [0..127] if Board.is_valid_square(i) expect(@board.piece_on(i)).toBeNull() describe "#place_piece", -&gt; it "should place a piece on the board", -&gt; piece = jasmine.createSpy("piece") @board.place_piece "a1", piece expect(@board.piece_on "a1").toEqual(piece) it "should set the piece's location to the given square's index", -&gt; piece = jasmine.createSpyObj(Piece, ["position"]) @board.place_piece "b5", piece expect(piece.position).toEqual(65) </code></pre> <p>[Edit]</p> <p>You can also add a <code>spec_helper</code> file (with the appropriate extension for your project) at the root of your <code>specs/</code> directory. Here's the contents of mine, which adds a new matcher to Jasmine:</p> <pre><code>jasmine = require('jasmine-node') beforeEach -&gt; this.addMatchers toInclude: (should_include) -&gt; for value in @actual return true if value == should_include false </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload