wechaty-puppet
Version:
Abstract Puppet for Wechaty
60 lines • 2.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tstest_1 = require("tstest");
const gerror_1 = require("gerror");
const puppet_skeleton_js_1 = require("./puppet-skeleton.js");
(0, tstest_1.test)('ProtectedPropertySkeleton', async (t) => {
const noOneLeft = true;
t.ok(noOneLeft, 'should match Mixin properties for every protected property');
});
(0, tstest_1.test)('emit(error, ...) with GError', async (t) => {
class PuppetSkeletonImpl extends puppet_skeleton_js_1.PuppetSkeleton {
}
const puppet = new PuppetSkeletonImpl();
const FIXTURES = [
undefined,
null,
true,
false,
0,
1,
'',
'foo',
[],
[1],
{},
{ foo: 'bar' },
new Error(),
new Error('foo'),
gerror_1.GError.from(new Error('test')),
];
let payload;
puppet.on('error', (...args) => {
payload = args[0];
});
for (const data of FIXTURES) {
puppet.emit('error', data);
await Promise.resolve();
t.equal(typeof payload.gerror, 'string', `should be an error payload for ${typeof data} "${JSON.stringify(data)}"`);
t.doesNotThrow(() => gerror_1.GError.fromJSON(payload.gerror), 'should be successfully deserialized to GError');
}
});
(0, tstest_1.test)('wrapAsync() promise', async (t) => {
class PuppetSkeletonImpl extends puppet_skeleton_js_1.PuppetSkeleton {
}
const puppet = new PuppetSkeletonImpl();
const spy = tstest_1.sinon.spy();
puppet.on('error', spy);
const DATA = 'test';
const promise = Promise.resolve(DATA);
const wrappedPromise = puppet.wrapAsync(promise);
t.equal(await wrappedPromise, undefined, 'should resolve Promise<any> to void');
const rejection = Promise.reject(new Error('test'));
const wrappedRejection = puppet.wrapAsync(rejection);
t.equal(wrappedRejection, undefined, 'should be void and not to reject');
t.equal(spy.callCount, 0, 'should have no error before sleep');
await new Promise(resolve => setImmediate(resolve)); // wait async event loop task to be executed
t.equal(spy.callCount, 1, 'should emit error when promise reject with error');
});
//# sourceMappingURL=puppet-skeleton.spec.js.map
;