> 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/test-variables.md).

# Test variables

We can test the variables, check their value during the course of the scenario.

### Local variable

```typescript
@Event('start')
start() {
    nb = 18
    > Give me a number
    Prompt()
    nb += :text
}
```

The test is as follows:

```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('Test variable', () => {
        return userConverse
            .start(testing => {
                const varNb = testing.variable('nb')
                assert.equal(varNb, 18)
            })
            .prompt('12', testing => {
                const varNb = testing.variable('nb')
                assert.equal(varNb, 30)
            })
            .end()
    })
})
```

With the `testing.variable()` method, we can test the value of a local variable

### Global variable

```typescript
$nb = 18

@Event('start')
start() {
    > Give me a number
    Prompt()
    $nb += :text
}
```

The test :

```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('Test global variable', () => {
        return userConverse
            .start(testing => {
                const varNb = testing.userVariable('nb')
                assert.equal(varNb, 18)
            })
            .prompt('12', testing => {
                const varNb = testing.userVariable('nb')
                assert.equal(varNb, 30)
            })
            .end()
    })
})
```

With the `testing.userVariable()` method, we can test the value of a global variable

### Magic variable

```typescript
@Event('start')
start() {
    > Your name ?
    Prompt()
    > Hello { :text }
}
```

The test :

```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('Test magic variable', () => {
        return userConverse
            .start()
            .prompt('Sam', testing => {
                const userName = testing.magicVariable('text')
                assert.equal(userName, 'Sam')

                const output = testing.output(0)
                assert.equal(output, 'Hello Sam')
            })
            .end()
    })
})
```

With the `testing.magicVariable()` method, we can test the value of a magic variable `:text`
