JS 구성 요소에서 마이그레이션 한 React 구성 요소가 있습니다. 나는 스터 빙이 더 이상 작동하지 않는 것 같기 때문에 테스트를 마친 후 검사를하고 많은 실패가 있습니다. 여기에 내가 가진 문제는 'ajaxStub.getCall (0)'null을 반환한다는 것입니다Enzyme 얕은 렌더링을 사용하여 Sinon과 스터 빙
describe("performs a DELETE AJAX request",() => {
it ("for specified URLs", sinon.test(function() {
let wrapper = shallow(<ActiveDeleteButton text = "Click Me" />);
let instance = wrapper.instance();
let ajaxStub = this.stub($, 'ajax');
instance.forceUpdate()
wrapper.update()
instance.handleConfirmDelete();
console.log(ajaxStub.getCall(0));
let options = ajaxStub.getCall(0).args[0];
assert.equal(options.url, objUt.deleteUri);
assert.equal(options.type, "DELETE");
}));
}));
...
import DeleteButton from "./delete-button.jsx"
import Dialogs from "../../dialogs";
import React from "react";
import UrlHelper from "../../helpers/url-helper";
export default class ActiveDeleteButton extends React.Component {
/**
* Creates an instance of ActiveDeleteButton.
*
* @param {object} props The react props collection.
*
* @memberOf ActiveDeleteButton
*/
constructor(props) {
super (props);
this.handleConfirmDelete = this.handleConfirmDelete.bind(this);
}
handleConfirmDelete() {
$.ajax({
url: this.props.deleteUri,
type: `DELETE`,
contentType: `application/json; charset=utf-8`,
cache: false,
success: (xhr) => {
let successUri = this.props.successUri;
if (!successUri && xhr && xhr.uri) { successUri = xhr.uri; }
if (successUri) { UrlHelper.redirect(successUri); }
},
error: (xhr, status) => {
this.showFailed();
}
});
}
/**
* Shows failure of deletion.
*
* @memberOf ActiveDeleteButton
*/
showFailed() {
Dialogs.alert(this.props.errorMessage);
}
/**
* Renders the component to the DOM.
*
* @returns the HTML to render.
*
* @memberOf ActiveDeleteButton
*/
render() {
return (
<DeleteButton text = {this.props.text}
title = {this.props.title}
cancelText = {this.props.cancelText}
confirmText = {this.props.confirmText}
message = {this.props.message}
onConfirmDelete = {this.handleConfirmDelete} />
);
}
}
을 내 구성 요소의 그리고 여기 (응축) 테스트입니다. 이것은 args를 검사 할 수 있도록 Ajax 호출을 반환해야한다. (예전의 JS 컴포넌트에서는 이전에 사용했다.) 스텁은 비록 내 마음에 분명히 있어야하지만 결코 호출되지 않습니다.
여기에 뭔가가 있습니까?