Skip to content

Commit

Permalink
Merge pull request #242 from iambumblehead/add-scoped-package-mock-test
Browse files Browse the repository at this point in the history
add scoped package mock test
  • Loading branch information
iambumblehead authored Sep 11, 2023
2 parents d953587 + bb33ee0 commit b38e18c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/local/importsScopedPackageClientS3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
S3Client
} from '@aws-sdk/client-s3'

export default new S3Client({
region: 'us-west-2',
credentials: {
accessKeyId: 'AKIARJOS8FJWB773G55',
secretAccessKey: 'secreataccessalkjsjdfoiwhe/gowh'
}
})
3 changes: 3 additions & 0 deletions tests/local/importsScopedPackageClientS3Deep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import s3 from './importsScopedPackageClientS3.js'

export default s3
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"#sub": "./local/subpath.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.408.0",
"babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault",
"eslint": "^8.12.0",
"form-urlencoded": "^6.0.7",
Expand Down
30 changes: 30 additions & 0 deletions tests/tests-node/esmock.node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,33 @@ test('should error when "strictest" mock tree module not mocked', async () => {
.replace(':parent', 'importsCoreLocalAndPackage.js'))
})
})

test('should mock scoped package, @aws-sdk/client-s3', async () => {
const scopedClientS3 = await esmock(
'../local/importsScopedPackageClientS3.js', {
'@aws-sdk/client-s3': {
S3Client: function () {
this.mocked = 'mock client'

return this
}
}
})

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

test('should mock scoped package, @aws-sdk/client-s3 (deep)', async () => {
const scopedClientS3 = await esmock(
'../local/importsScopedPackageClientS3Deep.js', {}, {
'@aws-sdk/client-s3': {
S3Client: function () {
this.mocked = 'mock client'

return this
}
}
})

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

0 comments on commit b38e18c

Please sign in to comment.