Solved

Requirejs and Jasmine BDD beforeEach calling Class not working

Posted on 2014-10-26
3
105 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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