-
-
Save imdongchen/b4fa8319b6e7516f9bc0da533a7466a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xhrMock from 'xhr-mock' | |
export class ApiMock extends Component<TProps> { | |
constructor(props: TProps) { | |
super(props) | |
this.mock() | |
} | |
componentWillUnmount() { | |
this.unmock() | |
} | |
render() { | |
return this.props.children | |
} | |
mock() { | |
this.unmock() | |
xhrMock.setup() | |
this.props.mocks.forEach(({ method, url, response })=> { | |
xhrMock.use(method, url, response) | |
}) | |
} | |
unmock() { | |
xhrMock.teardown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment