Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
68
Help us understand the problem. What is going on with this article?

More than 5 years have passed since last update.

@hmsk

Jasmine spec覚え書き

Suites and Specs

  • Suite -> describe
  • Spec -> it

JavaScript

describe("abstract suite", function() {
    it("abstract spec", function() {
        //spec
    });
    describe("concrete suite", function() {
        it("concrete spec1", function() {
            //spec
        });
        it("concrete spec2", function() {
            //spec
        });
    });
});

CoffeeScript

describe "abstract suite", ->
    it "abstract spec", ->
        #spec
    describe "concrete suite", ->
        it "concrete spec1", ->
            #spec
        it "concrete spec2", ->
            #spec

beforeEach / afterEach

describe内に書く。RSpecにおけるbefore do ~ end,after do ~ endを思い出す。

JavaScript

beforeEach(function() { 
    //doBefore
});

afterEach(function() {
    //doAfter
});

CoffeeScript

beforeEach ->
    #doBefore
afterEach ->
    #doAfter

Matchers

RSpecにおける.should be_xxxみたいなやつら。

toEqual

  • 同値であるかどうか
expect("string").toEqual("string");

toBe

  • 同オブジェクトであるかどうか
expect("object").toBe("object");

toBeTruthy / toBeFalsy

  • true / false であるかどうか
expect(evaluate).toBeTruthy();
expect(evaluate).toBeFalsy();

toMatch

  • 正規表現でマッチするかどうか
expect('hello and goodbye').toMatch(new RegExp('hello'));

toBeDefined

  • undefinedではないかどうか
var noop = function() {};
expect(noop).toBeDefined();

toBeNull

  • nullであるかどうか
expect(arg).toBeNull();

toContain

  • 配列に要素が、または文字列に文字列が含まれているかどうか
expect([1,2]).toContain(1);

toBeLessThan / toBeGreaterThan

  • 数値的に少ないかどうか / 多いかどうか
expect(arg).toBeLessThan();
expect(arg).toBeGreaterThan();

toThrow

  • 例外が投げられるかどうか
var err = function() {
    throw new TypeError;
};
expect(err()).toThrow();

.not

toXXXの頭に付けて否定

expect("object").not.toEqual("otherObject");
68
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
68
Help us understand the problem. What is going on with this article?