Skip to content

getting error "result is not iterable" while iterating result of ".find() of mocked data #138

Open
@sagargadekar601

Description

I am using document db with node.js and working on unit tests the "get" request.
I have mocked the data using mongo-mock (version 4.0.0). Added a jest unit test for the "get" request in node.js.

I could mock the data db data correctly (referred the demo example of npm mongo-mock) but while fetching the data with .find() it is giving an error which says "result is not iterable". This error doesn't occur in real time scenario, only happening in unit tests. Below is the code :

const result = await dbData.find(filter);
for await (let item of result) {

In result I see the correct data in count variable however it throws exception at "for" statement. I have mocked the data like below:

MongoClient.connect(url, {}, function(err, client) {
var db = client.db(""mydb);
// Get the documents collection
var collection = db.collection("myCollection");
// Insert some documents
var docs = "{"_id": "dbCollectionRecId",
"testtId": "testId"}";
//collection.insertOne(docs);
//insertMany
collection.insertOne(docs, function(err, result) {
console.log('inserted',result);
}
}

Let me know if I am missing anything.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions