jeudi 4 juin 2015

How to create QUnit tests with reference to another class?

I'm trying to add unit tests for JavaScripts into my web site. I use VS2013, project is ASP.NET web site.

Based on recommendations (http://ift.tt/1dR5dWx) I've done so far:

  1. Created new ASP.NET app
  2. Imported QUnit (using NuGet)
  3. Into "Scripts" added links to js-file in my original web site (files PlayerSkill.js - containts PlayerSkill class and trainings.js - contains Trainer and some other classes)
  4. Created new folder "TestScripts"
  5. Added TrainingTests.js file
  6. Wrote simple test:

    test( "Trainer should have non-empty group", function () { var group = "group"; var trainer = new Trainer(123, "Name123", group, 123);

        EQUAL(trainer.getTrainerGroup(), group);
    });
    
    

Notice: my trainings.js file among others contains

function Trainer(id, name, group, level) {
    ... 
    var _group = group;
    this.getTrainerGroup = function () { return _group ; }
};

When I execute my test I see error: Trainer is not defined.

It looks like reference to my class is not recognized. I feel like linking file is not enough, but what did I miss?

Please help add reference to the original file with class and run unit test.

Thank you.

P.S. Question 2: Can I add reference to 2 files (my unit test will require one more class which is in another file)? How?

Aucun commentaire:

Enregistrer un commentaire