Solved

Requirejs and Jasmine BDD beforeEach calling Class not working

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 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

11 Experts available now in Live!

Get 1:1 Help Now