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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:59:39+00:00 2026-06-06T19:59:39+00:00

In the following implementation of a hypothetical navigation module the module object returns properties

  • 0

In the following implementation of a hypothetical navigation module the module object returns properties such as isOverBinded or isNavTurnedOff which basically return the consequential value of other methods.

This methods are then utilised in the test cases to check whether a property call has caused its expected consequence.

Should these methods be kept or the original method in question return the consequential values and the same method to be used in the test case?

Currently the code is:

var navModule = (function(element) {

        var nav = {};

        var navHTMLobjs = {

            navList : element,

            listItems : element.find('li'),

            listLinks : element.find('a')

        };

        nav.bindOver = function() {

            navHTMLobjs.navList.on('mouseover mouseout', 'li a', function(e) {

                if (e.type == 'mouseover') {

                    $(this).addClass('over');

                }

                if (e.type == 'mouseout') {

                    $(this).removeClass('over');
                }

            });

        };

        nav.isOverBinded = function(){

            return navHTMLobjs.navList.data('events').hasOwnProperty('mouseover')

                && navHTMLobjs.navList.data('events').hasOwnProperty('mouseout');

        };

        nav.turnOff = function() {

            navHTMLobjs.navList.off('mouseover mouseout');

        };

        nav.isNavTurnedOff = function() {

            return !navHTMLobjs.navList.data.hasOwnProperty('events');

        };

        nav.init = function() {

            this.bindOver();

        };

        return nav;

    });

    var myNav = new navModule($('#nav'));

    /// Test cases:

    module('Navigation module');

    test('Binding total', function() {

        myNav.init();

        equal(myNav.isOverBinded(), true, "Does the init function attach all events?");

    });

    test('Unbinding total', function() {

        myNav.turnOff();

        equal(myNav.isNavTurnedOff(), true, "Does the cancel function correctly unbind events?");

    });

For example should I change nav.bingOver to be:

nav.bindOver = function() {

            navHTMLobjs.navList.on('mouseover mouseout', 'li a', function(e) {

                if (e.type == 'mouseover') {

                    $(this).addClass('over');

                }

                if (e.type == 'mouseout') {

                    $(this).removeClass('over');
                }

            });

            return navHTMLobjs.navList.data('events').hasOwnProperty('mouseover')

                && navHTMLobjs.navList.data('events').hasOwnProperty('mouseout');

        };

…and then use the same method in the test case like below?

test('Binding total', function() {

        myNav.init();

        equal(myNav.bindOver(), true, "Does the init function attach all events?");

    });

What are the differences between the two?

Many thanks

  • 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-06T19:59:40+00:00Added an answer on June 6, 2026 at 7:59 pm

    Assuming other parts of the app don’t need to independently verify whether the events have been subscribed to, the bindOver() should not return any value. Also, the isOverBinded() doesnt belong to the navigation module. Its existence is purely to help implement the test. In such a case, that function should be within the testing suite.

    var navModule = (function(element) {
    
        var nav = {};
    
        var navHTMLobjs = {
            navList : element,
            listItems : element.find('li'),
            listLinks : element.find('a')
        };
    
        nav.bindOver = function() {
            navHTMLobjs.navList.on('mouseover mouseout', 'li a', function(e) {
                if (e.type == 'mouseover') {
                    $(this).addClass('over');
                }
    
                if (e.type == 'mouseout') {
                    $(this).removeClass('over');
                }
            });
        };
    
        nav.turnOff = function() {
            navHTMLobjs.navList.off('mouseover mouseout');
        };
    
        nav.init = function() {
            this.bindOver();
        };
    
        return nav;
    });
    
    //var myNav = new navModule($('#nav'));
    
    /// Test cases:
    
    module('Navigation module');
    
    // you might already have such a in memory object 
    $root = $('<ul></ul>').append('<li><a href="#"></a></li><li><a href="#"></a></li>'); 
    var myNav = new navModule($root);
    
    test('Binding total', function() {
    
        myNav.init();
    
        equal(isOverBinded(), true, "Does the init function attach all events?");
    
    });
    
    test('Unbinding total', function() {
    
        myNav.turnOff();
    
        equal(isNavTurnedOff(), true, "Does the cancel function correctly unbind events?");
    
    });
    
    var isNavTurnedOff = function() {
        return $root.data('events').hasOwnProperty('mouseover') && $root.data('events').hasOwnProperty('mouseout');
    }
    
    var isOverBinded = function() {
        return $root.data.hasOwnProperty('events') === false;
    }
    

    At the end of the day I feel, whether or not the function ought to return a value should depend on the usage of the function and not for making testing easier.

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

Sidebar

Related Questions

So I have a class A in which I have the following: @implementation UIToolbar
Some scenarios to ponder. There is a legacy code which has following implementation Example1
I recently saw the following implementation of enqueue for a BlockingQueue ( source )
I have a problem with the following implementation of hook_cron in Drupal 6.1.3. The
Given I have two File objects I can think of the following implementation: public
The following XML implementation seems to work fine: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have this following codes: @implementation MyImageView @synthesize image; //image is a UIImage -
Take the following naive implementation of a nested async loop using the ThreadPool: ThreadPool.SetMaxThreads(10,
How can the following simple implementation of sum be faster? private long sum( int
I have the following code implementation of my generic singleton provider: public sealed class

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.