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 9146107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:40:37+00:00 2026-06-17T10:40:37+00:00

I am using node, mocha, and chai for my application. I want to test

  • 0

I am using node, mocha, and chai for my application. I want to test that my returned results data property is the same “type of object” as one of my model objects (Very similar to chai’s instance). I just want to confirm that the two objects have the same sets of property names. I am specifically not interested in the actual values of the properties.

Let’s say I have the model Person like below. I want to check that my results.data has all the same properties as the expected model does. So in this case, Person which has a firstName and lastName.

So if results.data.lastName and results.data.firstName both exist, then it should return true. If either one doesn’t exist, it should return false. A bonus would be if results.data has any additional properties like results.data.surname, then it would return false because surname doesn’t exist in Person.

This model

function Person(data) {
  var self = this;
  self.firstName = "unknown";
  self.lastName = "unknown";

  if (typeof data != "undefined") {
     self.firstName = data.firstName;
     self.lastName = data.lastName;
  }
}
  • 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-17T10:40:38+00:00Added an answer on June 17, 2026 at 10:40 am

    You can serialize simple data to check for equality:

    data1 = {firstName: 'John', lastName: 'Smith'};
    data2 = {firstName: 'Jane', lastName: 'Smith'};
    JSON.stringify(data1) === JSON.stringify(data2)
    

    This will give you something like

    '{firstName:"John",lastName:"Smith"}' === '{firstName:"Jane",lastName:"Smith"}'
    

    As a function…

    function compare(a, b) {
      return JSON.stringify(a) === JSON.stringify(b);
    }
    compare(data1, data2);
    

    EDIT

    If you’re using chai like you say, check out http://chaijs.com/api/bdd/#equal-section

    EDIT 2

    If you just want to check keys…

    function compareKeys(a, b) {
      var aKeys = Object.keys(a).sort();
      var bKeys = Object.keys(b).sort();
      return JSON.stringify(aKeys) === JSON.stringify(bKeys);
    }
    

    should do it.

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

Sidebar

Related Questions

I am using Node.js (with Express.js) to pass a JSON data object from the
I am writing a Node.js application that relies on RabbitMQ. I'm using node-amqp as
I'm using Mocha to test a small module in my Express.js application. In this
I am using the javascript test-runner Mocha. I have a test that is failing,
I'm using Node.js w/ node_redis and am looping through an object and looking up
I am using node.js to build a tcp server, and I want to extract
I've implemented the chat application using node.js. The program open the connection with the
I have to read, change and rewrite an HTML OBJECT tag using node.outerHTML. on
I am using node-fluent-ffmpeg module in NodeJS. It is very good that fluent-ffmpeg provides
I'm using node.js on EC2 I type EXPORT PORT=80 in terminal, and i see

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.