?
Solved

Requirejs and Jasmine BDD beforeEach calling Class not working

Posted on 2014-10-26
3
Medium Priority
?
106 Views
Last Modified: 2014-11-10
Hi,

I'm just learning jasmine and requirejs. I have this bit of code:

/*global describe, it, */
/*jshint -W117*/
define(
  [
    "js/helpers/HitPoints"
  ], 
  function( HitPoints ) {

    describe('Hitpoints stats', 
      function () {
        'use strict';

        var hitPoints = new HitPoints( 10, 10 );
        var oValues = hitPoints.getValues();

        /*beforeEach(function() {
          hitPoints = new HitPoints( 10, 10 );
          oValues = hitPoints.getValues();
        });*/

        it("has damages equal to expected from applyDamaage()", function () {

            hitPoints.setCallback( window , hitPoints.onHitsPointsChangedMan );
            hitPoints.applyDamage(2);

            expect(oValues.value).toEqual(2);
        });

        it("returns the values as objects", function () {
          //var oValues = hitPoints.getValues();

          expect(oValues).toBeDefined();
        });

    });

});

Open in new window


I'm trying to get the beforeEach currently commented out to work.

I tried using the this keyword too like (http://jasmine.github.io/2.0/introduction.html):

beforeEach(function() {
          this.hitPoints = new HitPoints( 10, 10 );
          this.oValues = hitPoints.getValues();
        });

Open in new window


But the other it() calls saying that this.hitPoints is undefined still. I changed the hitPoints variable to this.hitPoints in the it()  functions too.

Any  suggestions?

Thank you!
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
Victor Kimura earned 0 total points
ID: 40405704
Oh, I think this is the answer which makes it work now!

ref. http://www.sep.com/sep-blog/2014/07/16/jasmine-a-whole-new-world-of-javascript-testing-3/

        var hitPoints,
            oValues;

        beforeEach(function() {
          hitPoints = new HitPoints( 10, 10 );
          oValues = hitPoints.getValues();
        });

Open in new window

0
 
LVL 29

Expert Comment

by:pepr
ID: 40406874
OT: You can accept your own answer to close the question. This way, your points will be refunded to you, and the question stays here for the others who may find it useful later.
0
 

Author Closing Comment

by:Victor Kimura
ID: 40432322
Ok, thanks, pepr. =) Father God bless<><
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question