Skip to content

Commit 3f1930f

Browse files
authored
Merge pull request #7 from lumaghg/simple-example
added simple example and added the proxy mock as default export
2 parents 2a0f148 + 180bf02 commit 3f1930f

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

examples/simple_example/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run this test with ```deno test --import-map=./import_map.json exampletest.ts``` from this directory
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//prodCollection will be replaced by the mockCollection via import map
2+
import prodCollection from "./prodCollection.ts";
3+
import { MockCollection } from "../../mod.ts"
4+
import { Filter, FindOptions } from "https://deno.land/x/[email protected]/mod.ts"
5+
import {assertSpyCallAsync, Spy} from "https://deno.land/x/[email protected]/mod.ts"
6+
7+
//example function to be tested
8+
function exampleDatabaseCall() {
9+
prodCollection.findOne({ id: "example" }, {limit: 1})
10+
}
11+
12+
13+
Deno.test("simple example", () => {
14+
//define the MockCollections behaviour when calling the findOne function
15+
MockCollection.initMock({
16+
findOne: (_filter?: Filter<unknown> | undefined, _options?: FindOptions | undefined): Promise<unknown> => {
17+
return new Promise((resolve, _reject) => {
18+
resolve({ id:"example"})
19+
})
20+
}
21+
})
22+
23+
//execute the function
24+
exampleDatabaseCall()
25+
26+
//check whether the findOne Method was called correctly and returned the correct values
27+
assertSpyCallAsync(MockCollection.getInstance().findOne as Spy<any>, 0, {args: [{id: "example"}, {limit: 1}], returned: {id: "example"}})
28+
29+
})
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports":{
3+
"./prodCollection.ts" : "https://deno.land/x/denomongo_unittest_utils/mod.ts"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { MongoClient} from "https://deno.land/x/[email protected]/mod.ts"
2+
3+
interface IExample {
4+
id: string
5+
}
6+
7+
export default new MongoClient().database().collection("ExampleCollection")

0 commit comments

Comments
 (0)