Test a scenario
Type npm test in the terminal to run the unit tests
Perform a scenario test
Let's initialize the scenario
import { ConverseTesting } from 'newbot/testing'
import mainSkill from './main'
describe('My own test', () => {
let converse, userConverse
beforeEach(() => {
converse = new ConverseTesting(mainSkill)
userConverse = converse.createUser()
})
})The content of main.converse is as follows:
@Event('start')
start() {
> Hello
}The goal is to test if the message sent is Hello when the user interacts for the first time.
So let's add a test:
Let's use the
start()method to start the scenario. The function in parameter contains the argumenttesting. It will be used to perform several tests.Here, we use the
output()function to retrieve the first message sent by the script
Note that the
end()method returns a promise. Withmocha, we can return the promise toit()functionIt is possible to recover all messages sent by the script. For that, do not put parameters to the method.
Prompt test
The content of main.converse is now the following:
The test :
Note that the start() method performs all tests up to the input request. Then we use prompt() to enter a text (first parameter) and the scenario continues.
Perform a quick test of the conversation
It is possible to write a unit test more quickly if you want to test a simple conversation:
The scenario is always the following:
Last updated
Was this helpful?