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

  • Home
  • SEARCH
  • 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 9197727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:08:12+00:00 2026-06-17T22:08:12+00:00

I am testing an Express Node app with Mocha. I would like to have

  • 0

I am testing an Express Node app with Mocha. I would like to have the following test (comparing two empty arrays):

assert.equal [], []

to pass. However, Mocha gives me the following error:
AssertionError: [] == []

Which method should I use in order for comparison of two empty arrays to pass?

  • 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-17T22:08:13+00:00Added an answer on June 17, 2026 at 10:08 pm

    The problem is that an array is a reference type in JavaScript, and hence only the reference is compared. And, of course, if you create two different empty arrays independent of each other, they are two different objects and have two different references.

    That’s why the test fails.

    You basically have the same issues with objects (no deep-equal is done), although you often are not interested in whether two objects are identical, but whether their contents are the same.

    That’s why I wrote a module to handle this: comparejs. This module – besides some other nice things – solves this issue by offering comparison by value and comparison by identity, for all (!) types. I guess that’s what you need here.

    As you are especially asking for the context of mocha, I have also written my own assert-module, called node-assertthat, which internally makes use of comparejs. As a side effect, you get a more readable (as more fluent) syntax. Instead of

    assert.equal(foo, bar);
    

    you can write

    assert.that(foo, is.equalTo(bar));
    

    Perhaps this may be the way for you to go.

    PS: I know that self-advertisement is not wanted on Stackoverflow, but in this case the tools I’ve written for myself simply solve the original poster’s question. Hence please do not mark this answer as spam.

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

Sidebar

Related Questions

I have the following data strucutre outputting form my Schema in a node/express app.
I have an issue with testing my application with both jasmine-node and mocha (with
I have the following in my node server using Express (truncated to the important
I've just added shouldjs and mocha to my express app for testing, but I'm
I have a Node.js Express app that I'm hosting on Nodejitsu. I'm already using
With the following enabled: app.use(express.session({ store: sessionStore, secret: 'secret', key: 'express.sid'})); Whilst testing my
Testing.BSMain, Text: Start Page I would like to substring the value above and returning
I'm testing with node.js with express. Theoretically, If I run something very heavy calculation
I would like start to learn Visual Studio Unit Testing Framework on VS 2012
I use SQL Server 2005 Express user instances for unit testing. Each test randomly

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.