Skip to content

Commit

Permalink
Merge 9da89f0 into 2a0c7bd
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermatt committed Jul 15, 2019
2 parents 2a0c7bd + 9da89f0 commit 25f6ac3
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/scope.js
Expand Up @@ -137,28 +137,20 @@ Scope.prototype.options = function _options(uri, requestBody, options) {
return this.intercept(uri, 'OPTIONS', requestBody, options)
}

// Returns the list of keys for non-optional Interceptors that haven't been completed yet.
// TODO: This assumes that completed mocks are removed from the keyedInterceptors list
// (when persistence is off). We should change that (and this) in future.
Scope.prototype.pendingMocks = function pendingMocks() {
const self = this

const pendingInterceptorKeys = Object.keys(this.keyedInterceptors).filter(
function(key) {
const interceptorList = self.keyedInterceptors[key]
const pendingInterceptors = interceptorList.filter(function(interceptor) {
// TODO: This assumes that completed mocks are removed from the keyedInterceptors list
// (when persistence is off). We should change that (and this) in future.
const persistedAndUsed =
self._persist && interceptor.interceptionCounter > 0
return !persistedAndUsed && !interceptor.optional
})
return pendingInterceptors.length > 0
}
return this.activeMocks().filter(key =>
this.keyedInterceptors[key].some(({ interceptionCounter, optional }) => {
const persistedAndUsed = this._persist && interceptionCounter > 0
return !persistedAndUsed && !optional
})
)

return pendingInterceptorKeys
}

// Returns all keyedInterceptors that are active.
// This incomplete interceptors, persisted but complete interceptors, and
// This includes incomplete interceptors, persisted but complete interceptors, and
// optional interceptors, but not non-persisted and completed interceptors.
Scope.prototype.activeMocks = function activeMocks() {
return Object.keys(this.keyedInterceptors)
Expand Down

0 comments on commit 25f6ac3

Please sign in to comment.