Solved

Requirejs and Jasmine BDD beforeEach calling Class not working

Posted on 2014-10-26
3
99 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
  • 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 28

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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, …
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now