> 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/spy-a-function.md).

# Spy a function

Here is the following scenario:

```typescript
 @Event('start')
start() {
    > Hello
    yourName()
}

yourName() {
    name = 'sam'
}
```

What does the `yourName()` function contain? The unit test will be the following:

```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)
        userConverse = converse.createUser()
    })

    test('Spy', () => {
        return userConverse
            .start()
            .spy('yourName', testing => {
                const varName = testing.variable('name')
                assert.equal(varName, 'sam')
            })
            .end()
    })
})
```

With the `spy()` method, we can test the contents of the function (first parameter). The `testing.variable()` method is used to retrieve the value of a local variable.
