Skip to content

Commit

Permalink
Merge pull request #264 from altearius/mock-array
Browse files Browse the repository at this point in the history
Add unit testing demonstrating failure to mock an array
  • Loading branch information
iambumblehead authored Nov 4, 2023
2 parents 44b1420 + fab5794 commit fb78315
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/local/exportsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const exportedArray = [
{ name: "1" },
{ name: "2" },
{ name: "3" }
]

export default exportedArray
5 changes: 5 additions & 0 deletions tests/local/importsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import exportedArray from "./exportsArray.js"

export default function importsArray () {
return exportedArray
}
12 changes: 12 additions & 0 deletions tests/tests-node/esmock.node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,15 @@ test('should mock scoped package, @aws-sdk/client-s3 (deep)', async () => {

assert.strictEqual(scopedClientS3.mocked, 'mock client')
})

test('should mock an exported array', async () => {
const mockedArray = ['mocked']

const importsArray = await esmock(
'../local/importsArray.js', {
'../local/exportsArray.js': mockedArray
}
)

assert.deepStrictEqual(importsArray(), ['mocked'])
})

0 comments on commit fb78315

Please sign in to comment.