te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - karma jasmine not executing all tests - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - karma jasmine not executing all tests - Stack Overflow

programmeradmin3浏览0评论

so i have 6 karma jasmine tests, in one file i have 3, which im testing all my factories

the test file for the factory is as followed

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);
    });

});

in my console log its showing executed 4 of 6

PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 4 of 6 SUCCESS (0.004 secs / 0.029 secs)

So for some reason after the first it 'it' in the factory test file its skipping over the other two, even though there is no failures and all are contained in a beforeEach

so i have 6 karma jasmine tests, in one file i have 3, which im testing all my factories

the test file for the factory is as followed

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);
    });

});

in my console log its showing executed 4 of 6

PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 4 of 6 SUCCESS (0.004 secs / 0.029 secs)

So for some reason after the first it 'it' in the factory test file its skipping over the other two, even though there is no failures and all are contained in a beforeEach

Share Improve this question edited Jan 14, 2020 at 21:46 SoEzPz 15.9k8 gold badges64 silver badges66 bronze badges asked Jul 31, 2015 at 14:14 James KirkbyJames Kirkby 1,8345 gold badges26 silver badges46 bronze badges 4
  • show your other files. Also, you can bine your three beforeEach injectcts into just one beforeEach. – SoEzPz Commented Jul 31, 2015 at 15:06
  • which other files do you need to see? the tests or application, bining the injectors still results in same behaviour – James Kirkby Commented Jul 31, 2015 at 15:24
  • You are showing only three of the 6 tests. Where are the rest of them? Are any of the other tests running? What file is that 4th test ing from? show your karma.config as well. – SoEzPz Commented Jul 31, 2015 at 15:25
  • the other three tests are on controllers, the 4th one being executed is the first test in this factory test, i know this because if i change that test to an expression that fails it shows in the log – James Kirkby Commented Jul 31, 2015 at 15:28
Add a ment  | 

3 Answers 3

Reset to default 10

Further to the accepted answer, which is a much better structure for the tests anyway, I have found reproducible scenario for this: nested beforeEach sections found in a test cause Karma to stop running any further Jasmine tests. You can see in the question that it is indeed the case - the beforeEach's for the injects are within an outer beforeEach.

As part of a merge, one of our beforeEach lines that loads the module under test had been moved within a later beforeEach inadvertently. This was preventing all tests after that one running. Karma was reporting that x of y tests were running where x was 65 less than y, but that the test run was successful and there were none skipped.

So if you encounter this, check your report output for the last 'successfully' execute test (I say successfully in quotes as it's probably the one causing the issue) and see if that doesn't have nested beforeEach's in it.

Well then, let's start here. Change your file to this to clear a few things up and see if it goes away. You also need to define answers in the last test.

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!!!!
    });
  });
});

Also relevant:

It can also happen it there is an exception thrown before the tests hit any expect - this will not cause the test to be reported as failed - as it was never run. It will be shown as a reduced number of running tests. You can check your console logs for errors in that case.

发布评论

评论列表(0)

  1. 暂无评论