Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:00:36+00:00 2026-06-08T14:00:36+00:00

I was writing a DB test (runned by Mocha), calling findOne after saving a

  • 0

I was writing a DB test (runned by Mocha), calling findOne after saving a document and found a weird behavior:

pseudocode here:
…

test1
A.save(check('A',done));

test2
B.save(check('B',done));

test3
C.save(check('C',done));
...

check = function(name, done) {
   theModel.findOne({name:name}, function(err,result) {
       assert.notEqual(result,null);
       result.remove(done);
   });
}

Then, the A test passes BUT the B test doesnt pass. I check the logs and I find a curious thing:
first its performed a insert, after a query, after a remove (for the first test, ok thats the expected behaviour).
After the first test, I got shocked when I saw the query was performed BEFORE the insert (and so the test failed and nothing got removed).
The third and so on behaves the same way! query is performed before insert 🙁

So the only test which passes is the first one (if I change A by B, then B is passed and A isnt). If I look at the mongodb collection I can see the other inserts which were performed after the query (and since assert failed, they werent removed)

I’m using mongoose 2.7.2, (but i was using a previous version, just updated to see if it was a solved bug). Help 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:00:38+00:00Added an answer on June 8, 2026 at 2:00 pm

    I was wrong…

    Didnt notice I was actually calling check before calling save (since I was calling the function inside the save method … im so stupid and new to javascript).

    Ok so I should perform the check in other way:

    A.save(function(err, result) { check('A', done);})
    

    my apologizes!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn RSpec and writing test for CRUD actions. Here is my
I writing test cases for Android apps using Robotium. One of my test cases
In writing Test case as I know, first step/task is to identify the Test
I'm writing test code that needs to clean up the entities it creates when
I'm fairly new to writing test cases and this will be my first major
We want to design a simple domain specific language for writing test scripts to
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm writing a test case where I'm trying to use mockito to avoid entering
I am writing a test using easymock + powermock, the reason I am using
I'm writing some test cases, and I've got a test case that is using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.