ここでTDD Reactについて学んでいますが、以下のテスト状況を理解していません:
it('Correctly updates the state after AJAX call in `componentDidMount` was made', (done) => {
nock('https://api.github.com')
.get('/users')
.reply(200, [
{ 'name': 'Reign', 'age': 26 }
]);
// Overwrite, so we can correctly reason about the count number
// Don't want shared state
wrapper = mount(<UsersListComponent />);
setTimeout(function() {
expect(wrapper.state().usersList).to.be.instanceof(Array);
expect(wrapper.state().usersList.length).to.equal(1);
expect(wrapper.state().usersList[0].name).to.equal('Reign');
expect(wrapper.state().usersList[0].age).to.equal(26);
nock.cleanAll();
done();
}, 1500);
});
nockリクエストを偽造するために使用する目的は何ですか? このリクエストは何も実行せず、レスポンスがどこに送られるかわかりません。TDD のアプローチは、テスト (ラッパーで始まるコード) を作成し、それが失敗することを確認してから、実際のコンポーネントで実際の ajax 呼び出しを使用してテストすることだと思いました。ここでノックが何をするのかわかりません。