> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/javascript/getting-started.md).

# Getting Started (ok)

&#x20;Install Jest using [`yarn`](https://yarnpkg.com/en/package/jest):

```
yarn add --dev jest
```

Hãy bắt đầu bằng cách viết một bài kiểm tra cho một hàm giả định cộng hai số. Đầu tiên, tạo tệp ***sum.js***:

```
function sum(a, b) {
  return a + b;
}
module.exports = sum;
```

Sau đó, tạo một tệp có tên ***sum.test.js***. Điều này sẽ chứa thử nghiệm thực tế của chúng tôi:

```
const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});
```

&#x20;Add the following section to your ***`package.json`***

```
{
  "scripts": {
    "test": "jest"
  }
}
```

&#x20;Finally, run ***`yarn test`*** or ***`npm run test`*** and Jest will print this message:

### Running from command line

Bạn có thể chạy Jest trực tiếp từ CLI (nếu nó có sẵn trên toàn cầu trong PATH của bạn, ví dụ: bằng fiber global add jest hoặc npm install jest --global) với nhiều tùy chọn hữu ích.

Run all tests (default)

```
jest
```

Run all sum.test.js

```
jest sum.test or jest sum.test.js
```

&#x20;If you'd like to learn more about running `jest` through the command line, take a look at the [Jest CLI Options](https://jestjs.io/docs/cli) page.

#### Generate a basic configuration file

Based on your project, Jest will ask you a few questions and will create a basic configuration file with a short description for each option:

```
jest --init
```

#### Using Babel

&#x20;To use [Babel](https://babeljs.io/), install required dependencies via `yarn`:

```
yarn add --dev babel-jest @babel/core @babel/preset-env
```

&#x20;Configure Babel to target your current version of Node by creating a `babel.config.js` file in the root of your project:

```
// babel.config.js
module.exports = {
  presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://javascriptuse.gitbook.io/javascript/getting-started.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.
