Skip to content

Commit

Permalink
Made lazy table row comparison default
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchPierias committed Apr 23, 2019
1 parent fb19992 commit 0ab84ff
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,45 @@ export const sleep = async (delayInMs: number) =>
export const nextBlock = () => sleep(500);

/**
* Performs a comparison of table row query results against expected rows
* Compares table rows against expected rows irrespective of order
* @author Kevin Brown <github.com/thekevinbrown>
* @author Mitch Pierias <github.com/MitchPierias>
* @param getTableRowsResult Get table rows result promise
* @param expected Expected table row query results
* @param strict Strict comparison flag
*/
export const assertRowsEqual = async <RowType>(
getTableRowsResult: Promise<TableRowsResult<RowType>>,
expected: Array<RowType>
expected: Array<RowType>,
strict: boolean = false
) => {
// Call the table row query and assert results equal expected
// Pass-through strict comparison
if (strict) {
assertRowsEqualStrict(getTableRowsResult, expected);
return;
}
// Call table row query and assert results eventually equal expected
const result = await getTableRowsResult;
assert.deepEqual(result, {
// @ts-ignore - Not sure how to add this extended method `equalInAnyOrder`?
chai.expect(result).to.deep.equalInAnyOrder({
rows: expected,
more: false,
});
};

/**
* Compares table rows against expected rows irrespective of order
* Performs a strict comparison of queried table rows against expected rows
* @author Mitch Pierias <github.com/MitchPierias>
* @param getTableRowsResult Get table rows result promise
* @param expected Expected table row query results
*/
export const assertRowsEqualLazy = async <RowType>(
export const assertRowsEqualStrict = async <RowType>(
getTableRowsResult: Promise<TableRowsResult<RowType>>,
expected: Array<RowType>
) => {
// Call table row query and assert results eventually equal expected
// Call the table row query and assert results equal expected
const result = await getTableRowsResult;
// @ts-ignore - Not sure how to add this extended method `equalInAnyOrder`?
chai.expect(result).to.deep.equalInAnyOrder({
assert.deepEqual(result, {
rows: expected,
more: false,
});
Expand Down

0 comments on commit 0ab84ff

Please sign in to comment.