【问题标题】:Unit Test Rxjs 5单元测试 Rxjs 5
【发布时间】:2017-12-10 20:29:54
【问题描述】:

我正在尝试使用 mocha 和 chai 为我的可观察方法编写一个测试,该方法调用服务器并返回一些 json 数据。但是,当我运行测试时,出现以下错误: 错误:超过 2000 毫秒的超时。对于异步测试和钩子,确保调用“done()”;如果返回 Promise,请确保它已解决。 即使我覆盖了默认超时时间,我仍然会收到上述错误。我究竟做错了什么 ?

describe("some test", () => {
    let someClass: SomeClass;

    before(() => {
        someClass = new SomeClass();
    });
    ;

    it("should meet some condition", done => {

        let getData = someClass.getData('query')

        getData.subscribe(json => {
            json.success.should.equal(true);
            done();
        },
            done
        );

    });
});

【问题讨论】:

    标签: testing mocha.js chai rxjs5


    【解决方案1】:

    我找到了解决方案,我在 before 钩子中调用 done() 并在每个 it() 函数上设置超时。

    describe("some test", () => {
        let someClass: SomeClass;
    
        before((done) => {
            someClass = new SomeClass();
            done();
        });
        ;
    
        it("should meet some condition", done => {
    
            let getData = someClass.getData('query')
    
            getData.subscribe(json => {
                json.success.should.equal(true);
                done();
            },
                done
            );
        }).timeout(10000);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2013-02-26
      • 1970-01-01
      相关资源
      最近更新 更多