Test variables

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

Local variable

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

The test is as follows:

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

$nb = 18

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

The test :

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

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

The test :

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

Last updated