承诺没有显示测试结果的茉莉花

时间:2015-10-05 17:45:33

标签: node.js jasmine promise

所以我有一个非常基本的测试,我想在使用Jasmine的测试中检查Promise响应的类型。我正在运行一个节点项目,并设置了所有这些细节

describe('fail assertion', function() {
        it('should be a failure', function(done) {
            myvideopromise.then(function(resp) {
                expect(true).toBe(false);
                done();
            }).catch(done);
        });
    });

describe('list videos', function() {
        it('should return a list of videos', function(done) {
            myvideopromise.then(function(videos) {
                expect(Array.isArray(videos)).toBe(true);
                done();
            }).catch(done);
        });
    });

但是当我运行它时,我会在下面看到这一点。

Started
F.

Failures:
1) video suite fail assertion should be a failure
  Message:
    Expected true to be false.

“F”为红色,“。”是绿色的。所以看起来它正确地运行了测试断言,但是对于成功它似乎并没有显示成功消息。我需要传递旗帜还是什么东西?我正在使用

来调用它
jasmine JASMINE_CONFIG_PATH=test/jasmine_config.json

我的 jasmine_config.json 文件看起来像

{
    "spec_dir": "test/other/",
    "spec_files": [
        "video_tests.js"
    ]
}

1 个答案:

答案 0 :(得分:0)

describe('fail assertion', function () {
        it('should be a failure', function (done) {
            myvideopromise.then(function (resp) {
                expect(true).toBe(true);
                done();
            }).catch(e => {
                done(e);
            });
        });
    });

  describe('list videos', function () {
        it('should return a list of videos', function (done) {
            myvideopromise.then(function (videos) {
                expect(Array.isArray(videos)).toBe(true);
                done();
            }).catch(e => {
                done(e);// it's a failure case
            });
        });
    });
相关问题