UNPKG

@juzi/wechaty

Version:

Wechaty is a RPA SDK for Chatbot Makers.

93 lines 4.35 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm import { test } from 'tstest'; import PuppetMock from '@juzi/wechaty-puppet-mock'; import { WechatyEventEmitter } from '../schemas/wechaty-events.js'; import { // type AllProtectedProperty, WechatyImpl, // WechatyConstructor, } from './wechaty-impl.js'; test('Wechaty interface', async (t) => { class WechatyImplementation extends WechatyEventEmitter { Contact; ContactSelf; Delay; Friendship; Image; Location; Message; MiniProgram; Post; Room; RoomInvitation; Tag; TagGroup; UrlLink; Channel; ChannelCard; ConsultCard; PremiumOnlineAppointmentCard; Moment; CallRecord; ChatHistory; Wecom; DouyinOneClickPhoneCollection; ImSpecific; WxxdProduct; WxxdOrder; constructor() { super(); // this.puppet this.Contact = this.ContactSelf = this.Delay = this.Friendship = this.Image = this.Location = this.Message = this.MiniProgram = this.Post = this.Room = this.RoomInvitation = this.Tag = this.TagGroup = this.UrlLink = this.Channel = this.ChannelCard = this.ConsultCard = this.PremiumOnlineAppointmentCard = this.Moment = this.CallRecord = this.ChatHistory = this.Wecom = this.DouyinOneClickPhoneCollection = this.ImSpecific = this.WxxdProduct = this.WxxdOrder = {}; } } const WechatyTest = WechatyImplementation; const w = new WechatyTest(); w.on('message', (msg) => { msg.say('ok').catch(console.error); }); t.ok(typeof WechatyImplementation, 'should no typing error'); }); // test('ProtectedProperties', async t => { // won't work before wecom mixin // probably because node version change? // type NotExistInWechaty = Exclude<AllProtectedProperty, keyof WechatyImpl | `_${string}`> // type NotExistTest = NotExistInWechaty extends never ? true : false // const noOneLeft: NotExistTest = true // t.ok(noOneLeft, 'should match Wechaty properties for every protected property') // }) test('options.puppet initialization', async (t) => { const puppet = new PuppetMock(); const wechaty = new WechatyImpl({ puppet }); t.throws(() => wechaty.puppet, 'should throw when access puppet getter before init()'); await wechaty.init(); t.doesNotThrow(() => wechaty.puppet, 'should not throw when access puppet getter after init()'); t.ok(wechaty.puppet, 'should exist puppet instance by setting the options.puppet'); }); //# sourceMappingURL=wechaty-impl.spec.js.map