Relay mock module
import Relay from 'real-react-relay'; | |
export class Mutation extends Relay.Mutation { | |
_resolveProps(props) { | |
this.props = props; | |
} | |
} | |
export class MockStore { | |
reset() { | |
this.successResponse = undefined; | |
} | |
succeedWith(response) { | |
this.reset(); | |
this.successResponse = response; | |
} | |
failWith(response) { | |
this.reset(); | |
this.failureResponse = response; | |
} | |
update(callbacks) { | |
if (this.successResponse) { | |
callbacks.onSuccess(this.successResponse); | |
} else if (this.failureResponse) { | |
callbacks.onFailure(this.failureResponse); | |
} | |
this.reset(); | |
} | |
commitUpdate(mutation, callbacks) { | |
return this.update(callbacks); | |
} | |
applyUpdate(mutation, callbacks) { | |
return this.update(callbacks); | |
} | |
} | |
export const Store = new MockStore(); | |
export const Route = Relay.Route; | |
export const PropTypes = Relay.PropTypes; | |
export default { | |
QL: Relay.QL, | |
Mutation, | |
Route: Relay.Route, | |
PropTypes: Relay.PropTypes, | |
createContainer: (component, specs) => { | |
/* eslint no-param-reassign:0 */ | |
component.getRelaySpecs = () => specs; | |
return component; | |
}, | |
Store, | |
}; |
This comment has been minimized.
This comment has been minimized.
Do you know of any mock of relay modern that can be used in the same way as this one? |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hey mike, have you considered adding the ability to queue responses? With this implementation if you call commitUpdate within the success callback of another commitUpdate then both of the calls must have a failure response or a success response. It's not possible for one call to fail and the next one to succeed and vice versa. I have been using this code to mock tests and it has been very helpful so far but this seems like it would be a helpful addition. Just wanted to let you know! Thanks!