私はこのarticleからTDDを学びました。著者は、MochaのbeforeEach
があなたのためにどのようにコードを実行するのかについて話します。しかし、私はあなたが記述スコープでコードを実行するだけのときになぜそれを行う必要があるのか理解していません。#describeスコープ内でコードを実行できるのは、Mochaの#beforeEachの目的は何ですか?
describe('Test suite for UserComponent',() => {
beforeEach(() => {
// Prevent duplication
wrapper = shallow(<UserComponent
name={ 'Reign' }
age={ 26 } />);
});
it('UserComponent should exist',() => {
expect(wrapper).to.exist;
});
it('Correctly displays the user name and age in paragraphs wrapped under a parent div',() => {
expect(wrapper.type()).to.equal('div');
// more code...
});
});
しかしbeforeEach
はまだ動作します使用していない -
describe('Test suite for UserComponent',() => {
wrapper = shallow(<UserComponent
name={ 'Reign' }
age={ 26 } />);
it('UserComponent should exist',() => {
expect(wrapper).to.exist;
});
it('Correctly displays the user name and age in paragraphs wrapped under a parent div',() => {
expect(wrapper.type()).to.equal('div');
// more code...
});
});
各テストの前にajaxリクエストを呼び出す場合は、またはDBリクエスト?または明確な変数? – Maxx