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

Commit

Permalink
fix: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 21, 2018
1 parent b05f03f commit 939fb4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export * from './chai'

import test from './test'
export {test}
import test, {Test, TestBase} from './test'

export {
Test,
TestBase,
test,
}
export default test
19 changes: 13 additions & 6 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export type DescribeCallback = TestCallback <mocha.ISuiteCallbackContext, {}, vo
export type Extensions = [{[k: string]: object}, {[k: string]: [object, any]}]

export interface It<C> {
(expectation: string, cb: ItCallback<C>): mocha.ITest
only(expectation: string, cb: ItCallback<C>): mocha.ITest
skip(expectation: string, cb: ItCallback<C>): void
(expectation: string, cb?: ItCallback<C>): mocha.ITest
only(expectation: string, cb?: ItCallback<C>): mocha.ITest
skip(expectation: string, cb?: ItCallback<C>): void
}

export interface Describe {
(expectation: string, cb: DescribeCallback): mocha.ISuite
only(expectation: string, cb: DescribeCallback): mocha.ISuite
skip(expectation: string, cb: (this: mocha.ISuiteCallbackContext) => void): void
skip(expectation: string, cb?: (this: mocha.ISuiteCallbackContext) => void): void
}

export interface TestBase<E extends Extensions, C = {}> {
Expand Down Expand Up @@ -119,9 +119,14 @@ const test = <F extends Extensions = [{}, {}]>(previous?: Test<any, any>): TestB
return context
}
const _catch = async (err: Error, context?: object) => {
let handled = false
for (let f of filters) {
if (f.catch) await f.catch(context, err)
if (f.catch) {
await f.catch(context, err)
handled = true
}
}
return handled
}
const _finally = async (context?: object) => {
for (let f of filters) {
Expand All @@ -142,7 +147,9 @@ const test = <F extends Extensions = [{}, {}]>(previous?: Test<any, any>): TestB
await after(context)
} catch (err) {
error = err
await _catch(err)
if (await _catch(err)) {
error = false
}
} finally {
await _finally()
}
Expand Down

0 comments on commit 939fb4a

Please sign in to comment.