来自async
的Angular @angular/core/testing
似乎并未解决async
测试中的超时问题,因为async
之前有import { async } from "@angular/core/testing";
describe("test async", () => {
let count: number = 0;
beforeEach(async(() => {
count++;
console.log('async before test ' + count);
setTimeout(() => {
console.log('timeout before test ' + count);
}, 1000);
}))
it("async test 1", async(() => {
console.log('starting test 1');
setTimeout(() => {
console.log('test 1 finished');
console.log('expected count: 1, actual count: ' + count);
expect(count).toBe(1, "should be test 1");
}, 2000);
}));
it("async test 2", async(() => {
console.log('starting test 2');
setTimeout(() => {
console.log('test 2 finished');
console.log('expected count: 2, actual count: ' + count);
expect(count).toBe(2, "should be test 2");
}, 2000);
}));
it("async test 3", async(() => {
console.log('starting test 3');
setTimeout(() => {
console.log('test 3 finished');
console.log('expected count: 3, actual count: ' + count);
expect(count).toBe(3, "should be test 3");
}, 2000);
}));
});
同样。
不幸的是,我还没有能够在任何类型的Plunkr或JSFiddle上重现这个bug。
重新创建它的最简单方法是简单地创建一个全新的Angular CLI应用程序并将此代码粘贴到app.component.spec.ts中:
async before test 1
timeout before test 1
starting test 1
async before test 2
timeout before test 2
starting test 2
async before test 3
test 1 finished
expected count: 1, actual count: 3
timeout before test 3
starting test 3
test 2 finished
expected count: 2, actual count: 3
test 3 finished
expected count: 3, actual count: 3
如果您随后运行此测试,您应该看到如下输出:
async before test 1
timeout before test 1
starting test 1
test 1 finished
expected count: 1, actual count: 1
async before test 2
timeout before test 2
starting test 2
test 2 finished
expected count: 2, actual count: 2
async before test 3
timeout before test 3
starting test 3
test 3 finished
expected count: 3, actual count: 3
但是根据我的理解这是不正确的,因为测试中的超时应该在下一次测试开始之前完成,这是异步的全部要点。
如果输出正常,输出将是这样的:
require 'redis-rack'
use Rack::Session::Redis, :redis_server => "redis://#{ENV['REDIS_HOST']}:6379/0"
非常感谢任何帮助,谢谢!