2016-11-07 6 views
0

「を期待して」投げ...シンプル活字体ジャスミンのテストは、私は次のような単純なジャスミンのテストを持っているエラー

//test.spec.ts 
describe('Sample', function(){ 
    it('Should do something',() => expect(true).toBe(true)); 
}); 

しかし、私は私が手に実行...

Error: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out 

これはうまく動作します。 ..

describe('Sample', function(){ 
    it('Should do something', function(){ 
     expect(true).toBe(true); 
    }); 
}); 

答えて

3

チェックをこれら二つの文がある場合、これはplayground

describe('Sample', function(){ 
    it('Should do something', 
     () => expect(true).toBe(true)); 
}); 

describe('Sample', function(){ 
    it('Should do something',() => { 
     expect(true).toBe(true)); 
    } 
}); 

彼らはDIFになり

簡単にしようと、チェックします私たちはここに

を必要としないferent JSコード {}をラップなし

describe('Sample', function() { 
    it('Should do something', function() { return expect(true).toBe(true); }); 
}); 
describe('Sample', function() { 
    it('Should do something', function() { 
     expect(true).toBe(true); 
    }); 
}); 

簡単な文は、return文にtranspiledされ、

0

あなたがそれを得ている理由は、スコープを別の方法で次に扱う矢印機能です 機能。

it('Should do something', function() { 
    expect(true).toBe(true); 
}); 

機能がthisとしてスペックで実行されていますが、矢印の機能を使用する場合:

あなたはこれをやっているとき

it('Should do something',() => { 
    expect(true).toBe(true); 
}); 

thisは異なっています。

it('Should do something', function() { 
    console.log("this is: ", this); 
    expect(true).toBe(true); 
}); 

そして:

it('Should do something',() => { 
    console.log("this is: ", this); 
    expect(true).toBe(true); 
}); 
関連する問題