Solved

Requirejs and Jasmine BDD beforeEach calling Class not working

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article discusses how to create an extensible mechanism for linked drop downs.
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 how to dynamically set the form action using jQuery.

829 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