Comments (6)
I run the test with both v3.28.0 and v3.34.0 of @aws-sdk/client-secrets-manager
and it looks to work fine.
The code you posted has a slight mistake - you either pass the client class to the mockClient()
function, or the same instance that you want to mock.
This works good for me:
import {mockClient} from 'aws-sdk-client-mock';
import {GetSecretValueCommand, SecretsManagerClient} from '@aws-sdk/client-secrets-manager';
it('mocks SecretsManagerClient', async () => {
const smMock = mockClient(SecretsManagerClient);
smMock.on(GetSecretValueCommand)
.resolves({
SecretString: JSON.stringify({my_secret_key: 'my_secret_value'}),
});
const sm = new SecretsManagerClient({});
const response = await sm.send(new GetSecretValueCommand({
SecretId: 'qq',
}));
expect(response.SecretString).toBe('{"my_secret_key":"my_secret_value"}');
});
Alternatively, if you want to mock only a single instance of the Client, you need to provide the same instance in the mock as you use later in code:
import {mockClient} from 'aws-sdk-client-mock';
import {GetSecretValueCommand, SecretsManagerClient} from '@aws-sdk/client-secrets-manager';
it('mocks SecretsManagerClient', async () => {
const sm = new SecretsManagerClient({});
const smMock = mockClient(sm);
smMock.on(GetSecretValueCommand)
.resolves({
SecretString: JSON.stringify({my_secret_key: 'my_secret_value'}),
});
const response = await sm.send(new GetSecretValueCommand({
SecretId: 'qq',
}));
expect(response.SecretString).toBe('{"my_secret_key":"my_secret_value"}');
});
Please let me know if that solves your problem.
from aws-sdk-client-mock.
Hey, I was vacationing so sorry for the delay, but I will look into this in the next days.
from aws-sdk-client-mock.
Just bumping this to see if there's any ideas/updates?
from aws-sdk-client-mock.
Just wanted to reopen this because I got the same error (ExpiredTokenException: The security token included in the request is expired
).
It seems you need to have valid credentials / token to access your AWS account from the CLI for it to work. I don't expect you'd need these set to do a mocked unit test 😅
from aws-sdk-client-mock.
@Brawrdon can you create a sample repository with problem reproduction? As noted above, I did mock Secrets Manager successfully.
from aws-sdk-client-mock.
Okay so very strange... It seems to work fine now even though my tokens expired so now I'm finding it hard to recreate the error.
from aws-sdk-client-mock.
Related Issues (20)
- toHaveReceivedCommand should throw an error if it receives a second parameter. HOT 2
- Ability pass a Sinon Sandbox HOT 1
- not compatible with "@aws-sdk/xxx": "3.451.0" HOT 5
- Deprecated [email protected] library
- Solution to types not compatible with @aws-sdk/* version 3.xxx.x
- Support `toHaveReceivedAnyCommand` HOT 1
- Add repository object/homepage key to package.json HOT 2
- Fail to stub entirely QueryCommand - DynamoDB HOT 2
- Testing SDK Retries HOT 3
- Upload throws error when using mocked S3 client HOT 3
- Types is not working for aws-sdk 3.362.0 HOT 4
- AwsStub issues HOT 3
- SQSClient received matching "DeleteMessageCommand" 0 times, after "SendMessageCommand" is run HOT 1
- NodeJS 20 mocking Upload doesn't work HOT 1
- Question: how to list/print configured client beheviours? HOT 1
- calls() does not return calls made from exception handler HOT 1
- 3.1.0 / 4.0.0 breaks existing test-suite/build with Invalid Chai property: toHaveReceivedCommandWith on vitest HOT 3
- Asymmetric Matchers not working HOT 4
- Jest matcher expect().toEqual() throws error "TypeError: this.customTesters is not iterable" HOT 4
- s3 mock: You are trying to `import` a file after the Jest environment has been torn down. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-client-mock.