Jasmine允许深度嵌套描述套件有多深?

时间:2015-08-25 18:40:06

标签: javascript unit-testing jasmine

我试图以这种方式嵌套它们,似乎它停在describe("When...spec2 child", function () {开始的层面。

我想知道Jasmine允许嵌套套房的深度是多少?或者我做错了什么?

describe("ModelSpec", function () {
  /*Initial Test Properties*/
  var Subject = require('../../lib/jasmine_examples/Model');
  var Data = require('../../lib/jasmine_examples/MockData');
  var input = new Data();
  var model = new Subject(input);//service itself
  var mock = {
    truthy : true,
    falsy : false,
    obj : {},
    arr : [],
    arrOfObj : [ { } ],
    nul : null,
    undef : undefined,
  };
  beforeEach(function () {

  });
  it("Spec 1", function () {
    expect(model).toBeDefined();
  });
  it("Spec 1.2", function () {
    expect(model).toBeDefined();
  });


  describe("When...", function () {
    /*
    You can initiate another set of test properties vars here
    */
    beforeEach(function () {
    });
    it("Spec 2", function () {
      expect(model).toBeDefined();
      describe("When...spec2 child", function () {
        beforeEach(function () {
        });
        it("Spec 2 child", function () {
        });
      });
    });

    it("Spec 3", function () {
      expect(model).toBeDefined();
      expect(input.id).toBeDefined();


    });
  });

1 个答案:

答案 0 :(得分:1)

您无法在describe内加it。嵌套没有固定的限制。

使用:

describe("...", function() {
  describe("...", function() {
    it("...", function() {
      // ...
    });

    describe("...", function() {
      // ...
    });
  });
});

不能工作:

describe("...", function() {
  describe("...", function() {
    it("...", function() {
      describe("...", function() {
        // ...
      });
    });
  });
});