Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: fixed done callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 26, 2018
1 parent a5c73b0 commit 5ef8df8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
}
if (context.error) throw context.error
}
return context.test(arg1, (cb && cb.length === 2) ? done => run(done) : () => run())
function runWithDone(done: MochaDone) {
run(done).catch(done)
}
return context.test(arg1, (cb && cb.length === 2) ? runWithDone : () => run())
}
return {
...Object.entries(context.plugins)
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface PluginDef {
export interface Plugins {[k: string]: PluginDef}

export interface It<I> {
(expectation: string, cb?: (context: I, done?: MochaDone) => any): void
(cb?: (context: I, done?: MochaDone) => any): void
(expectation: string, cb?: (context: I, done: MochaDone) => any): void
(cb?: (context: I, done: MochaDone) => any): void
}

export type Base<I extends Context, T extends Plugins> = {
Expand Down
16 changes: 16 additions & 0 deletions test/finally.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ describe('finally', () => {
.finally(() => {})
.it('finally')
})

describe('done', () => {
// fancy
// .do(() => {throw new Error('x')})
// .it('calls done', (_, done) => {
// done('foo')
// })
// fancy
// .it('calls done', (_, done) => {
// done('foo')
// })
fancy
.it('calls done', (_, done) => {
done()
})
})

0 comments on commit 5ef8df8

Please sign in to comment.