0
在陣營應用程序,我想測試Ajax調用陣營採用摩卡與興農
click事件由一種方法來處理JS測試Ajax:
_search =() => {
AppActions.search({
url: this.props.url,
queryValue: query
})
}
這調用方法上商店這使得一個Ajax調用:
onSearch (req) {
$.get(url)
.done((data) => {
// set state...
})
}
我試圖用興農存根jQuery的AJAX調用:
describe('Search', function() {
describe('Rendering', function() {
beforeEach(() => {
sinon.stub($, 'ajax')
let component = TestUtils.renderIntoDocument(<MockComponent />)
this.renderedDOM = ReactDOM.findDOMNode(component)
})
afterEach(() => {
$.ajax.restore()
})
it('Should make an ajax request',() => {
TestUtils.Simulate.click(myButton)
// expect stubbed ajax call to have been made with args etc
})
})
})
任何人都知道我應該怎麼做,這樣我可以:
- 存根Ajax調用
- 調用回調或
- 檢查存根Ajax調用事先
謝謝