私はTDDについて学んだがhereを反応させ、下記のテストの状況を理解していない:テストで模擬ajax呼び出しを使用する目的は何ですか?
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呼び出しを使用してテストを参照してください。私はここでノックが何をするのか見ていない。