# Core Concepts

## Helper functions

`sls-jest` comes with a set of helper functions which represent AWS resources (e.g. `dynamoDbItem()`, `s3Object()`). They are used in combination with matchers in order to perform assertions. They serve several purposes:

* **Validation**

Jest technically allows any value in the `expect()` function, but all values can't be used with all `matchers` (e.g. `expect(123).toExist()` does not make sense). `sls-jest` uses those helper functions in order to check whether a matcher can be used with the input value you are passing. If they are not compatible, an error will be thrown.

Basic validation is also done on the values that are passed in the helper functions. e.g. with `dynamodbItem()`, the `tableName` and `key` attributes are required.

* **Reuseability**

Some matchers can be used with several resources. e.g. You can do `expect(dynamodbItem(...)).toExist();` or `expect(s3Object(...)).toExist();`.

`sls-jest` uses those helpers to keep track of **what** you are intending to test and use the appropriate logic internally.

* **First-class TypeScript support**

You will get intellisense support for valid `expect` and matchers input values, and only matchers that are compatible with the specified helper will be allowed.

* **Readability**

Thanks to those helpers, code becomes much easier to read and more natural-language.

e.g. `expect(dynamodbItem(...)).toExist();`

## Spies

Spies work similarly to [Jest Function Spies](https://jestjs.io/docs/mock-function-api). They let you spy on a some serverless resources such as an [EventBridge](/sls-jest/spies/eventbridge.md) bus.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://serverlessguru.gitbook.io/sls-jest/core-concepts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
