Closed hcfw007 closed 2 years ago
@huan I trined a new way to handle async test this time, is this kinda async/await style you mentioned?
is this kinda async/await style you mentioned?
No, it's not the async/await style. It's still the callback style.
Instead of (callback style)
await puppet.start()
.then(() => {
t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')
t.pass('memory test pass')
return null
})
.catch(async e => {
await puppet.stop()
t.fail(`cannot start puppet due to ${e as any}`)
})
The async/await style should be:
try {
await puppet.start()
t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')
t.pass('memory test pass')
} catch (e) {
await puppet.stop()
t.fail(`cannot start puppet due to ${e as any}`)
}
after await puppet.start(), puppet.stop() will be called, does this affect puppet's state?
start
/stop
of course will affect the state.
What's the state
in your context?
I mean if I wrote
puppet.on('scan', () => {puppet.stop()}
await puppet.start()
t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')
will this puppet.memory.payload effected by puppet.stop()?
I'm not sure about it.
My suggestion would be just write a unit test to confirm the behavior and make sure it's what you are expecting.
336