有没有办法停止执行(调度)组件内部的功能或动作,将在使用笑话的反应测试中挂载。
我有以下代码:
import {
resetAutocomplete
} from "../../actions/ui/autocomplete";
class AutocompleteInput extends Component {
static propTypes = {
title: PropTypes.string,
tabIndex: PropTypes.number.isRequired,
getSuggestedItem: PropTypes.func.isRequired,
searchItem: PropTypes.func.isRequired,
getName: PropTypes.func.isRequired,
selectItem: PropTypes.func.isRequired,
autocomplete: PropTypes.object.isRequired,
resetAutocomplete: PropTypes.func.isRequired
};
componentWillMount = () => {
const { resetAutocomplete } = this.props;
resetAutocomplete();
};
};
在我的测试中: test.js
const initialState = {
ui: {
autocomplete: {
loading: false,
search: "test",
results: [],
selected: null
}
}
};
let persist;
const store = configureStore((persist = false), initialState),
wrapper = mount(
<Provider store={store}>
<AutocompleteInput
title={"Test"}
tabIndex={10}
getSuggestedItem={() => {}}
searchItem={() => {}}
getName={() => {}}
selectItem={() => {}}
/>
</Provider>
);
但是由于“ resetAutocomplete()”,我的自动完成值始终会重置。如何避免这种情况?我在这里想念什么?我在开玩笑。