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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:54:02+00:00 2026-06-07T17:54:02+00:00

I have a controller which is depended on a model property. I wrote a

  • 0

I have a controller which is depended on a model property.
I wrote a test which test this controller and stubbed the model, How can I make my controller test fail whenever the model property name changes?

Here is an example:

Model:

function Model(obj){
  this.id = obj.id; 
  this.name = obj.name;
}

Controller:

function Controller( model ){
  this.model = model
};
Controller.prototype.showName = function() { 
  return this.model.name; 
}

Controller test:

describe("A controller", function(){

  var controller = new Controller( new Model({id:1, name: "john"}) );

  it ("should show the person name", function(){
    expect(controller.showName).toEqual("john");
  });

});

I want this test to fail whenever the “name” property changes to something else, something like “name2”.

Anyone got a good suggestion on how to do it in javascript?

Thanks,
Shai

  • 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-07T17:54:03+00:00Added an answer on June 7, 2026 at 5:54 pm

    Since the model is exposed you can check for the existence of the property.

    expect(controller.name).toBeDefined();
    

    On the other hand, this test would fail anyway if the property of the model was renamed and the controller wouldn’t be altered too.

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

Sidebar

Related Questions

I have a controller which has two methods: upload and submit I can ensure
I have this controller which performs me a multiple domain databinding class, and it
I''d like to have the controller which can process soemthing like http:// * /query/id
I have a controller which renders a view (~/Views/Component/Create.aspx) no problem. When this view
I have a controller which peforms a linq to sql query against a model
I have this controller which will simply change the language in a session so
I have a controller which uses AJAX for CRUD, however whenever I click on
I have a controller which loads the view like this: class A extends Controller{
Will keep this as simple a possible:- I have a have a controller which
I have a controller servlet which forward the request to the model servlet.Now when

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.