业力茉莉花没有执行所有测试

Jam*_*kby 6 unit-testing jasmine angularjs karma-jasmine

所以我有6个业力茉莉花测试,在一个文件中我有3个,我测试我所有的工厂

工厂的测试文件如下

describe('Quiz Factories', function() {

    beforeEach(function() {

        //Ensure angular modules available
        beforeEach(module('geafApp'));

        beforeEach(inject(function (_counter_) {
            counter = _counter_;
        }));

        beforeEach(inject(function (_answer_sheet_) {
            answer_sheet = _answer_sheet_;
        }));

        beforeEach(inject(function (_questions_) {
            questions = _questions_;
        }));

    });

    it('it should return a number', function () {
        expect(counter).toBeNumber();
    });

    it('it should return an empty object', function () {
        expect(answer_sheet).toBeEmptyObject();
    });

    it('it should return an empty object', function () {
        expect(questions).toHaveObject(answers);
    });

});
Run Code Online (Sandbox Code Playgroud)

在我的控制台日志中显示执行4中的4

PhantomJS 1.9.8(Mac OS X 0.0.0):执行4中6成功(0.004秒/0.029秒)

所以出于某种原因,在工厂测试文件的第一个'它'之后它跳过其他两个,即使没有失败并且所有都包含在beforeEach中

Jus*_*tin 9

除了接受的答案,这是一个更好的测试结构,我已经找到了可重复的场景:嵌套在测试中找到的每个部分导致Karma停止运行任何进一步的Jasmine测试.你可以在问题中看到它确实是这种情况 - 注射的beforeEach是在一个外部的beforeEach之内.

作为合并的一部分,我们的一个加载被测模块的beforeEach行已经在之前的一个之内被无意中移动了.这阻止了那次运行之后的所有测试.Karma报告说,y测试中有x个测试正在运行,其中x比y小65,但测试运行成功且没有跳过.

因此,如果您遇到这种情况,请检查您的报告输出,以查看最后一次"成功"执行测试(我说成功引用了引号,因为它可能是引起问题的那个)并查看它是否没有嵌套beforeEach.


SoE*_*zPz 3

那么,我们就从这里开始吧。将您的文件更改为此以清除一些内容并查看它是否消失。您还需要在上次测试中定义答案。

describe('Quiz Factories', function() {

  var counter, answerSheet, questions;

  beforeEach( function(){
    module( 'geafApp' );

    inject( function( _counter_, _answer_sheet_, _questions_ ){
      counter = _counter_;
      answerSheet = _answer_sheet_;
      questions = _questions_;
    });
  });

  describe( 'when a question is asked', function(){
    it( 'should return a number', function(){
      expect( counter ).toBeNumber();
    });

    it( 'should return an empty object', function(){
      expect( answerSheet ).toBeEmptyObject();
    });

    it( 'should return an empty object', function(){
      expect( questions ).toHaveObject( answers ); // ??? answers is not defined!!!!
    });
  });
});
Run Code Online (Sandbox Code Playgroud)