Skip to content

Instantly share code, notes, and snippets.

@asn007
Created February 24, 2018 11:16
Show Gist options
  • Save asn007/ae34a550289de8588ef685ab81952374 to your computer and use it in GitHub Desktop.
Save asn007/ae34a550289de8588ef685ab81952374 to your computer and use it in GitHub Desktop.
class QueryBuilderMock {
static forClass() {
return new this()
}
modelClass = () => ({ tableName: 'model_mock' })
_mergeContext = jest.fn().mockReturnThis()
_patch = jest.fn().mockReturnThis()
_delete = jest.fn().mockReturnThis()
_where = jest.fn().mockReturnThis()
mergeContext(...args) {
return this._mergeContext.apply(null, args)
}
patch(...args) {
return this._patch.apply(null, args)
}
delete(...args) {
return this._delete.apply(null, args)
}
where(...args) {
return this._where.apply(null, args)
}
}
class ModelMock {
static query() {
return this.QueryBuilder.forClass(this)
}
static get QueryBuilder() {
return QueryBuilderMock
}
static namedFilters = {
someFilter: () => {},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment