Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
TypeError: undefined is not an object when unit testing with jasmine - JSON response

I added this line in an existing unit test which used to work and I'm getting an error after adding this:(BTW, this works ok on web browser.)

onRender: function () {
    if ( _.isEmpty(this.viewData.assessment) || _.isEmpty(this.viewData.patient) || _.isEmpty(this.viewData.scoreInfo) ) {
      $("#viewAssessmentDetails").hide();
      return;
    }
    //console.log("this.viewData.scoreInfo: ",JSON.stringify(this.viewData.scoreInfo));
    if (this.completedAssessment) {
      this.viewData.assessment = this.completedAssessment.toJSON();
    }
    
   //without this line, the test passes
   this.viewData.assessment.format.sections[0].questions[0].introText =
      this.viewData.assessment.format.sections[0].questions[0].introText.replace(/\|/g, '\n');
...
...

the error I get:

FAILED TESTS:

viewAssessmentDetails
    ✖ render no completed assessment renders
      PhantomJS 2.1.1 (Mac OS 0.0.0)
    TypeError: undefined is not an object (evaluating 'this.viewData.assessment.format.sections') in src/test/view/app/view_assessment_detailsSpec.js (line 49131)
    onRender@webpack:///src/js/view/app/view_assessment_details.js:368:5 <- src/test/view/app/view_assessment_detailsSpec.js:49131:72948
    webpack:///src/test/view/app/view_assessment_detailsSpec.js:253:9 <- src/test/view/app/view_assessment_detailsSpec.js:50821:88
    <Jasmine>

    ✖ render with completed assessment renders
      PhantomJS 2.1.1 (Mac OS 0.0.0)
    TypeError: undefined is not an object (evaluating 'this.viewData.assessment.format') in src/test/view/app/view_assessment_detailsSpec.js (line 49131)
    onRender@webpack:///src/js/view/app/view_assessment_details.js:368:5 <- src/test/view/app/view_assessment_detailsSpec.js:49131:72941
    webpack:///src/test/view/app/view_assessment_detailsSpec.js:265:9 <- src/test/view/app/view_assessment_detailsSpec.js:50840:88
    <Jasmine>

thanks in advance, Daniel

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!