This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
-
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 resolvesNext not accepting sync iterable and improve examples (#26)
- Loading branch information
Showing
11 changed files
with
340 additions
and
364 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { delay } from "https://deno.land/std@0.114.0/async/delay.ts"; | ||
export type { DelayOptions } from "https://deno.land/std@0.114.0/async/delay.ts"; | ||
export { delay } from "https://deno.land/std@0.115.1/async/delay.ts"; | ||
export type { DelayOptions } from "https://deno.land/std@0.115.1/async/delay.ts"; | ||
|
||
export { | ||
assert, | ||
|
@@ -10,7 +10,7 @@ export { | |
assertRejects, | ||
assertStrictEquals, | ||
assertThrows, | ||
} from "https://deno.land/std@0.114.0/testing/asserts.ts"; | ||
} from "https://deno.land/std@0.115.1/testing/asserts.ts"; | ||
|
||
export { RBTree } from "https://deno.land/x/[email protected]/trees/rb_tree.ts"; | ||
export { ascend } from "https://deno.land/x/[email protected]/comparators.ts"; | ||
|
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
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
import { assertEquals } from "../deps.ts"; | ||
import { | ||
assertSpyCallAsync, | ||
assertSpyCalls, | ||
resolvesNext, | ||
Stub, | ||
stub, | ||
} from "../mod.ts"; | ||
|
||
class Database { | ||
query(_query: string, _params: unknown[]): Promise<unknown[][]> { | ||
throw new Error("unimplemented"); | ||
} | ||
} | ||
|
||
async function getUsers( | ||
db: Database, | ||
lastName: string, | ||
firstName?: string, | ||
): Promise<string[]> { | ||
return (await db | ||
.query( | ||
"SELECT id, username FROM users WHERE last_name=?" + | ||
(firstName ? " and first_name=?" : ""), | ||
firstName ? [lastName, firstName] : [lastName], | ||
)) | ||
.map((row) => `${row[0]} ${row[1]}`); | ||
} | ||
|
||
Deno.test("getUsers", async () => { | ||
const db: Database = new Database(); | ||
const resolves: [number, string][][] = [ | ||
[[1, "jd"], [2, "johnd"], [3, "janedoe"]], | ||
[[2, "johnd"]], | ||
]; | ||
const query: Stub<Database> = stub(db, "query", resolvesNext(resolves)); | ||
|
||
try { | ||
assertEquals(await getUsers(db, "doe"), ["1 jd", "2 johnd", "3 janedoe"]); | ||
assertEquals(await getUsers(db, "doe", "john"), ["2 johnd"]); | ||
|
||
resolves.push([[3, "janedoe"]]); | ||
assertEquals(await getUsers(db, "doe"), ["3 janedoe"]); | ||
|
||
await assertSpyCallAsync(query, 0, { | ||
args: [ | ||
"SELECT id, username FROM users WHERE last_name=?", | ||
["doe"], | ||
], | ||
self: db, | ||
returned: [[1, "jd"], [2, "johnd"], [3, "janedoe"]], | ||
}); | ||
|
||
await assertSpyCallAsync(query, 1, { | ||
args: [ | ||
"SELECT id, username FROM users WHERE last_name=? and first_name=?", | ||
["doe", "john"], | ||
], | ||
self: db, | ||
returned: [[2, "johnd"]], | ||
}); | ||
|
||
await assertSpyCallAsync(query, 2, { | ||
args: [ | ||
"SELECT id, username FROM users WHERE last_name=?", | ||
["doe"], | ||
], | ||
self: db, | ||
returned: [[3, "janedoe"]], | ||
}); | ||
|
||
assertSpyCalls(query, 3); | ||
} finally { | ||
query.restore(); | ||
} | ||
}); |
Oops, something went wrong.