Spy a function

Here is the following scenario:

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

yourName() {
    name = 'sam'
}

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

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.

Last updated