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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:26:04+00:00 2026-05-23T10:26:04+00:00

I want to be able to test some inner functions that I have without

  • 0

I want to be able to test some inner functions that I have without putting the Javascript test code in the same file. I’ve been trying to inherit the class that has the inner functions, and then adding wrapper functions to make them public, like this:

copyPrototype(TrafficChartCanvas_test, TrafficChartCanvas);

function TrafficChartCanvas_test() {

    TrafficChartCanvas_test.prototype.test_getYScale = function(reach) {
        return getYScale(reach);
    }
}

Assume copyPrototype successfully assigns the prototype of TrafficChartCanvas to that of TrafficChartCanvas_test. Here’s part of the file I’m attempting to test:

function TrafficChartCanvas(...) {

    // some other stuff here... public functions, etc.

    function getYScale(reach) {
        ...
    }
}

However, this doesn’t work for me. Is there any other way I can do this?

  • 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-23T10:26:04+00:00Added an answer on May 23, 2026 at 10:26 am

    getYScale isn’t part of TrafficChartCanvas‘s prototype, it’s within its closure. They’re two very different things.

    You could change the way you create TrafficChartCanvas and restructure your code something like:

    TrafficChartCanvas.prototype = {
      // (... Other functions ...)
      getYScale: function() {
          ...
      }
    }
    

    This puts the function in the prototype and allows it to be tested using tests written and included in another file. You can’t keep functions private within a closure and make the accesible for external testing; you’ll have to go the prototype route.

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

Sidebar

Related Questions

I have some values that I want to be able to set, and the
Using Nunit, I want to be able to write a test fixture that will
I want to be able to take an image that i have already captured
I am new to VB. I want to test some old VB code, but
I am writing an Nspec to test some file manipulation. I want to be
I have some integration tests that test the processing of USB data from a
I want to be able to execute Behat based test scenarios within Jenkins. Behat
I want to be able to split a big test to smaller tests so
To test an app I'm building, I want to be able to emulate the
I want to have a generic PHP function that builds a mysql query based

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.