Skip to main content

Puppet Provider: Mock

Wechaty Puppet Mock

Wechaty Puppet Mock

NPM Version npm (tag)

Features#

  1. Help to test Wechaty framework with a mock puppet
  2. Using as a starter template for write your own puppet provider

Usage#

npm install wechaty-puppet-mock
export WECHATY_PUPPET=wechaty-puppet-mock
npm start

Mocker & Environment#

import {
PuppetMock,
Mocker,
SimpleEnvironment,
} from 'wechaty-puppet-mock'
const mocker = new Mocker()
mocker.use(SimpleEnvironment())
const puppet = new PuppetMock({ mocker })
const wechaty = new Wechaty({ puppet })
wechaty.start()
// The Mocker will start perform the SimpleEnvironment...

See: SimpleEnvironment

API Reference#

Mocker#

import { Wechaty } from 'wechaty'
import {
PuppetMock,
mock,
} from 'wechaty-puppet-mock'
const mocker = new mock.Mocker()
const puppet = new PuppetMock({ mocker })
const bot = new Wechaty({ puppet })
await bot.start()
mocker.scan('https://github.com/wechaty', 1)
const user = mocker.createContact()
mocker.login(user)
const contact = mocker.createContact()
const room = mocker.createRoom()
user.say('Hello').to(contact)
contact.say('World').to(user)

Example: unit testing for math_master game#

math_master is a Wechaty Vorpal Contrib command which is a simple game for answering math questions that asked by a Wechaty bot.

Math Master Wechaty Game

You can read the unit testing script at: https://github.com/wechaty/wechaty-vorpal-contrib/blob/master/src/contrib/math_master/math_master.spec.ts

Roadmap#

  • to be added

History#

See: Project README

Maintainers#

Last updated on by Souvik Biswas