I use mocha, an enzyme and expect my testing. I have a function in my component that runs another function that returns a promise, and I donβt know how to check the behavior of the first before it runs the second function and then check the promise (get the error after .then)
1st function:
handleUpdateInput (value) { const { access, onUpdateInput } = this.props const v = !value || typeof value === 'string' ? value : access(value) if (onUpdateInput) { onUpdateInput(value ? v : '') } this.setState({ searchText: value }) this.dataSourceUpdate(value) }
Second function:
dataSourceUpdate (value) { const { promise, access } = this.props if (value === '') { this.autoCompleteData = [] this.setState({ dataSource: [] }) } else { promise(value) .then(res => { this.autoCompleteData = res.data this.setState({ dataSource: this.autoCompleteData.map(access).slice(0, getMenuItemNumber(this.refs.customAutoComplete)) }) }) .catch(() => { this.autoCompleteData = [] this.setState({ dataSource: [] }) }) } }
I would also like to send me a good tutorial for testing asynchronous functions using these tools :)
source share