it('should be a test',function(){runs(function(){this.foo=0this.foo++;varbar=0;bar++;expect(this.foo).toEqual(1);expect(bar).toEqual(1);});runs(function(){this.foo++;varbar=0bar++;expect(this.foo).toEqual(2);expect(bar).toEqual(1);});});

waits(timeout) 这个方法和runs()一起使用，我们可以通过该方法来指定阻塞多久再执行下一个runs()

12345678910111213141516171819

it('should be a test',function(){runs(function(){this.foo=0;varthat=this;setTimeout(function(){that.foo++;},250);});runs(function(){expect(this.foo).toEqual(0);});waits(500);runs(function(){expect(this.foo).toEqual(1);});});

describe('waitsFor Test',function(){it('after 2sec, it will be true',function(){variWillBeTrue=false;setTimeout(function(){iWillBeTrue=true;},2000);waitsFor(function(){returniWillBeTrue;},"maybe i will never be true",10000);runs(function(){expect(iWillBeTrue).toEqual(true);});});});

waitsFor Test
after 2sec, it will be trueFailures:
1) after 2sec, it will be trueMessage:
timeout: timed out after 10000 msec waiting for maybe i will never be trueStacktrace:
undefined
Finished in 10.921 seconds
1 test, 1 assertion, 1 failure