Skip to content

Commit

Permalink
fix falsy module mock
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Dec 17, 2020
1 parent e0cdfa7 commit 7f6245c
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ are the same used in ${filename} require calls`)
this.mocks.set(mockFilePath, mocks[key])
}

function tapRequireMock (id) {
const requiredFilePath = Module._resolveFilename(id, this)
const res = self.mocks.get(requiredFilePath)

if (res)
return res

return Module.prototype.require.call(this, id)
}

class MockedModule extends Module {
require (id) {
return tapRequireMock.call(this, id)
const requiredFilePath = Module._resolveFilename(id, this)

if (self.mocks.has(requiredFilePath))
return self.mocks.get(requiredFilePath)

return super.require(id)
}
}

Expand Down

0 comments on commit 7f6245c

Please sign in to comment.