UNPKG

1.84 kBPlain TextView Raw
1#!/usr/bin/env ts-node
2
3/**
4 * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
5 *
6 * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
7 * Wechaty Contributors <https://github.com/wechaty>.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 */
22import test from 'blue-tape'
23import sinon from 'sinon'
24
25import { PuppetMock } from 'wechaty-puppet-mock'
26
27import {
28 Wechaty,
29} from './wechaty'
30import { WechatyPlugin } from './plugin'
31
32test('Wechaty Plugin uninstaller should be called after wechaty.stop()', async t => {
33 const spyPluginInstall = sinon.spy()
34 const spyPluginUninstall = sinon.spy()
35
36 const bot = new Wechaty({ puppet: new PuppetMock() })
37
38 const plugin: WechatyPlugin = (_bot: Wechaty) => {
39 spyPluginInstall()
40 return () => {
41 spyPluginUninstall()
42 }
43 }
44
45 t.true(spyPluginInstall.notCalled, 'should be clean for install spy')
46 t.true(spyPluginUninstall.notCalled, 'should be clean for uninstall spy')
47
48 bot.use(plugin)
49 t.true(spyPluginInstall.called, 'should called install spy after use()')
50 t.true(spyPluginUninstall.notCalled, 'should not call uninstall spy after use()')
51
52 await bot.start()
53 await bot.stop()
54
55 t.true(spyPluginUninstall.called, 'should called uninstall spy after stop()')
56})