@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
79 lines • 3.27 kB
JavaScript
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;
Moment;
CallRecord;
ChatHistory;
Wecom;
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.Moment
= this.CallRecord
= this.ChatHistory
= this.Wecom
= {};
}
}
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