Some usefule jasmine terms and its wiki pages

1 Suites and specs

 

1.1 Specs

Each spec is, naturally, a JavaScript function. You tell Jasmine about a spec with a call to it() with a description string and the function. The string is a description of a behavior that you want your production code to exhibit; it should be meaningful to you when reading a report.

it('should increment a variable', function () {
  var foo = 0;
  foo++;
});

1.2 Suites

Specs are grouped in Suites. Suites are defined using the global describe() function:

describe('Calculator', function () {
  it('can add a number', function () {
  ...
  });

  it('can multiply some numbers', function () {
  ...
  });
});

1.3 Disabling Tests & Suites

Specs may be disabled by calling xit() instead of it(). Suites may be disabled by calling xdescribe() instead of describe().

2 Matchers

Jasmine has several built-in matchers. Here are a few:

3 Spies

Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors. A 'spy' replaces the function it is spying on.

4 Before and After

A suite can have a beforeEach() declaration. It takes a function that is run before each spec.


Post by: Jalen Wang (转载请注明出处)

posted on 2012-03-06 21:20  Jalen Wang  阅读(186)  评论(0编辑  收藏  举报

导航