> For the complete documentation index, see [llms.txt](https://docs.newbot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.newbot.io/unit-tests/create-a-mock.md).

# Create a mock

The purpose of the mock is to distort the return of a function. This can be useful, for example for an HTTP request

```javascript
import assert from 'assert'
import { ConverseTesting } from 'newbot/testing'
import mainSkill from './main'

describe('My own test', () => {
    let converse, userConverse

    beforeEach(() => {
        converse = new ConverseTesting(mainSkill)
        converse.mock('Request', (url) => {
            return {
                statusCode: 200
            }
        })
        userConverse = converse.createUser()
    })

    test('Test fonction return', () => {
        return userConverse
            .start(testing => {
                const { statusCode } = testing.magicVariable('response')
                assert.equal(statusCode, 200)
            })
            .end()
    })
})
```

And the ConverseScript code:

```typescript
@Event('start')
start() {
    Request('https://jsonplaceholder.typicode.com/users')
}
```

So we use the `mock()` method to mock a function in the ConverseScript
