提交 bd5f2d0a 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix unit tests

上级 ed136098
......@@ -180,44 +180,6 @@ test('clickSwitchAccount()', async t => {
})
})
// test('retryPromise()', async t => {
// const EXPECTED_RESOLVE = 'Okey'
// const EXPECTED_REJECT = 'NotTheTime'
// function delayedFactory(timeout: number) {
// const startTime = Date.now()
// return function() {
// const nowTime = Date.now()
// if (nowTime - startTime > timeout) {
// return Promise.resolve(EXPECTED_RESOLVE)
// }
// return Promise.reject(EXPECTED_REJECT)
// }
// }
// const thenSpy = spy()
// const retryPromise = require('retry-promise').default
// const delay500 = delayedFactory(500)
// await retryPromise({ max: 1, backoff: 1 }, function() {
// return delay500()
// }).catch((e: any) => {
// thenSpy(e)
// })
// t.true(thenSpy.withArgs(EXPECTED_REJECT).calledOnce, 'should got EXPECTED_REJECT when wait not enough')
// thenSpy.resetHistory()
// const anotherDelay50 = delayedFactory(50)
// await retryPromise({ max: 6, backoff: 10 }, function() {
// return anotherDelay50()
// })
// .then((r: string) => {
// thenSpy(r)
// })
// t.true(thenSpy.withArgs(EXPECTED_RESOLVE).calledOnce, 'should got EXPECTED_RESOLVE when wait enough')
// })
test('WechatyBro.ding()', async t => {
const profile = new Profile(Math.random().toString(36).substr(2, 5))
const bridge = new Bridge({
......
......@@ -216,6 +216,9 @@ test('findAll()', async t => {
;
(wechaty as any).initPuppetAccessory(puppet)
const sandbox = sinon.createSandbox()
sandbox.stub(puppet, 'contactPayload').resolves({})
const MOCK_USER_ID = 'TEST-USER-ID'
puppet.login(MOCK_USER_ID)
......@@ -224,6 +227,8 @@ test('findAll()', async t => {
})
t.is(msgList.length, 2, 'Message.findAll with limit 2')
sandbox.restore()
})
test('self()', async t => {
......
......@@ -357,7 +357,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
await userSelf.ready()
this.id = userId
console.log('this.id=', this.id)
// console.log('this.id=', this.id)
this.emit('login', userId)
}
......
......@@ -77,6 +77,7 @@ test('event:start/stop', async t => {
await wechaty.start()
await wechaty.stop()
// console.log(startSpy.callCount)
t.ok(startSpy.calledOnce, 'should get event:start once')
t.ok(stopSpy.calledOnce, 'should get event:stop once')
})
......
......@@ -530,19 +530,24 @@ export class Wechaty extends PuppetAccessory implements Sayable {
break
case 'start':
puppet.removeAllListeners('start')
puppet.on('start', () => {
this.emit('start')
} )
break
case 'stop':
puppet.removeAllListeners('stop')
puppet.on('stop', () => {
this.emit('stop')
} )
// do not emit 'start'/'stop' again for wechaty
break
// case 'start':
// puppet.removeAllListeners('start')
// puppet.on('start', () => {
// this.emit('start')
// } )
// break
// case 'stop':
// puppet.removeAllListeners('stop')
// puppet.on('stop', () => {
// this.emit('stop')
// } )
// break
case 'friend':
puppet.removeAllListeners('friend')
puppet.on('friend', payload => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册