UNPKG

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