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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:06:03+00:00 2026-05-26T01:06:03+00:00

The last Unit Test of in the following code fails, probably because the ==

  • 0

The last Unit Test of in the following code fails, probably because the == operator, which is used by the equals(), doesn’t compare the Arrays properly. However, I can’t figure out why this happens.

Why does equals() fail when comparing an Array retrieved from an SC.Record to a newly instantiated Array?

monster_model.js

BagOfTricks.Monster = SC.Record.extend(
{
  name: SC.Record.attr(String, { defaultValue: 'Unspecified' }),
  level: SC.Record.attr(Number, { defaultValue: 0 }),
  keywords: SC.Record.attr(Array, { defaultValue: function() { return [ 'Unspecified' ] } })
}
);

monster_test.js

var defaultMonster;

module("BagOfTricks.Monster", {
    setup: function() {
        defaultMonster = BagOfTricks.store.createRecord( BagOfTricks.Monster, {} );
    },
    teardown: function() {
        BagOfTricks.store.reset();
    }
}
);

test("Default monster created as expected?", function() {
    equals(defaultMonster.get('name'), 'Unspecified');
    equals(defaultMonster.get('level'), 0);

    // The following test fails.
    var defaultKeywordArray = ['Unspecified'];
    equals(defaultKeywordArray, defaultMonster.get('keywords'));
}
);
  • 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-05-26T01:06:03+00:00Added an answer on May 26, 2026 at 1:06 am

    JavaScript behaves quite strangely when it comes to comparing arrays. I can’t tell you why, but I can tell you how to avoid it.

    Use the second function from Breaking Par: JavaScript Are Arrays Equal.

    It is type-safe and quite fast on large arrays.

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

Sidebar

Related Questions

I was writing some Unit tests last week for a piece of code that
I have this following python code, it works fine in python but fails with
In my unit test (which extends ActivityInstrumentationTestCase2<> ) I need to assert the new
I have a code, that compare the last timestamp with the actual timestamp. If
I need to test my controller which does Response.Redirect() at the last line. But
for last three days i am trying to create unit test case using OcUnit.
Im using the Prism/Composite Application Library and trying to unit test some code that
Using the following simplified test, webdriver fails to find the intended element no matter
How can I unit test a method which uses a session object inside of
I have a unit test that is used to test variable conversions from string

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.