-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): wrap test loops in assertions
- Loading branch information
Showing
4 changed files
with
246 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect } from 'chai'; | ||
|
||
export function itFails(msg: string, done: Mocha.Done, count = 1): Mocha.TestFunction { | ||
const expectations: Array<Chai.PromisedAssertion> = []; | ||
|
||
const mockIt = function (this: Mocha.Context, name: string, test: Mocha.AsyncFunc) { | ||
console.log('mock it invoked with test', name, test.name, expectations.length); | ||
|
||
expectations.push(expect(test.call(this), name).to.eventually.be.rejectedWith(Error, `Property failed ${msg}`)); | ||
|
||
if (expectations.length >= count) { | ||
console.log('all expectations queued for', name, expectations.length); | ||
|
||
Promise.all(expectations).then((_val) => done(), (err) => done(err)); | ||
} | ||
}; | ||
|
||
return (mockIt as unknown as Mocha.TestFunction); | ||
} | ||
|
||
export function itPasses(done: Mocha.Done, count = 1): Mocha.TestFunction { | ||
const expectations: Array<Chai.PromisedAssertion> = []; | ||
|
||
const mockIt = function (this: Mocha.Context, name: string, test: Mocha.AsyncFunc) { | ||
console.log('mock it invoked with test', name, test.name, expectations.length); | ||
|
||
expectations.push(expect(test.call(this), name).to.eventually.be.oneOf([true, undefined])); | ||
|
||
if (expectations.length >= count) { | ||
console.log('all expectations queued for', name, expectations.length); | ||
|
||
Promise.all(expectations).then((_val) => done(), (err) => done(err)); | ||
} | ||
}; | ||
|
||
return (mockIt as unknown as Mocha.TestFunction); | ||
} |
Oops, something went wrong.