You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/parameters.md
+55-2
Original file line number
Diff line number
Diff line change
@@ -134,7 +134,7 @@ By default, the provider will cache parameters retrieved in-memory for 5 seconds
134
134
135
135
You can adjust how long values should be kept in cache by using the param `maxAge`, when using `get()` or `getMultiple()` methods across all providers.
136
136
137
-
```typescript hl_lines="7 10" title="Caching parameters values in memory for longer than 5 seconds"
137
+
```typescript hl_lines="7 11" title="Caching parameters values in memory for longer than 5 seconds"
@@ -397,3 +397,56 @@ The **`clientConfig`** parameter enables you to pass in a custom [config object]
397
397
```typescript hl_lines="2 4-5"
398
398
--8<--"docs/snippets/parameters/clientConfig.ts"
399
399
```
400
+
401
+
## Testing your code
402
+
403
+
### Mocking parameter values
404
+
405
+
For unit testing your applications, you can mock the calls to the parameters utility to avoid calling AWS APIs. This can be achieved in a number of ways - in this example, we use [Jest mock functions](https://jestjs.io/docs/es6-class-mocks#the-4-ways-to-create-an-es6-class-mock) to patch the `getParameters` function.
With this pattern in place, you can customize the return values of the mocked function to test different scenarios without calling AWS APIs.
418
+
419
+
A similar pattern can be applied also to any of the built-in provider classes - in this other example, we use [Jest spyOn method](https://jestjs.io/docs/es6-class-mocks#mocking-a-specific-method-of-a-class) to patch the `get` function of the `AppConfigProvider` class. This is useful also when you want to test that the correct arguments are being passed to the Parameters utility.
In some other cases, you might want to mock the AWS SDK v3 client itself, in these cases we recommend using the [`aws-sdk-client-mock`](https://www.npmjs.com/package/aws-sdk-client-mock) and [`aws-sdk-client-mock-jest`](https://www.npmjs.com/package/aws-sdk-client-mock-jest) libraries. This is useful when you want to test how your code behaves when the AWS SDK v3 client throws an error or a specific response.
Parameters utility caches all parameter values for performance and cost reasons. However, this can have unintended interference in tests using the same parameter name.
446
+
447
+
Within your tests, you can use `clearCache` method available in [every provider](#built-in-provider-class). When using multiple providers or higher level functions like `getParameter`, use the `clearCaches` standalone function to clear cache globally.
0 commit comments