1

I am new to jasmine.js framework.

What is the problem in this code:

beforeEach(function(){
     var fixtureUrl     = "/../path/to/templates/home.html";
     var html = jasmine.getFixtures().read(fixtureUrl);
     console.log(html);
});

I am getting a error:

TypeError: undefined is not a function at Object.

TypeError: undefined is not a function at Object<anonymous> (http://{MY_LOCAL_DOMAIN}/test/jasmine2/spec/home.view.spec.js:15:23)
    at attemptSync (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1510:12)
    at QueueRunner.run (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1498:9)
    at QueueRunner.execute (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1485:10)
    at Spec.Env.queueRunnerFactory (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:518:35)
    at Spec.execute (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:306:10)
    at Object.<anonymous> (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1708:37)
    at attemptAsync (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1520:12)
    at QueueRunner.run (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1496:16)
    at QueueRunner.execute (http://{MY_LOCAL_DOMAIN}/test/jasmine2/libs/jasmine-2.0.0/jasmine.js:1485:10)

I am using: Jasmine.js, Jasmine-html.js and boot.js from jasmine version 2.0.0 and Jasmine-jQuery Version 2.1.0

In my application, I am using spec.config.js to load all necessary file includes: in this order:

 paths: {
     ...,
     ...,
     ...,
    'jasmine': '../test/jasmine2/libs/jasmine-2.0.0/jasmine',    
    'jasmine-html':'../test/jasmine2/libs/jasmine-2.0.0/jasmine-html',    
    'boot': '../test/jasmine2/libs/jasmine-2.0.0/boot',    
    'jasmine-jquery':'../test/jasmine2/libs/jasmine-2.0.0/jasmine-jquery',    
    'sinon': '../test/jasmine2/libs/sinon-1.9.1/sinon',
}

And I have defined into my spec file as:

 describe('Home', function() {   

     define(['views/home.view','jasmine','jasmine-jquery'], function(HomeView,Jasmine,JasmineJQuery) {
    ....
         var home_view      = new HomeView();
         var jasmine        = Jasmine;
         var jasmine_jquery = JasmineJQuery;
    ....
    });
    beforeEach(function(){
         var fixtureUrl     = "/../path/to/templates/home.html";
         var html = jasmine.getFixtures().read(fixtureUrl);
         console.log(html);
    });
    it('should check home is rendred', function() {
          {SOME TESTING HERE...}
    });

});

Can any one help me to read fixtures data and check toHaveId("{SOME_DIV_ID}")?

1 Answer 1

3

You have to order the .js files in this order:

<script type="text/javascript" src="../jasmine2/libs/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="../jasmine2/libs/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="../jasmine2/libs/jasmine-2.0.0/boot.js"></script>
<script type="text/javascript" src="../../js/libs/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="../jasmine2/libs/jasmine-2.0.0/jasmine-jquery.js"></script>

In your spec file, you can globally defined your view object as:

 describe('View', function() {
     'use strict';
     {VARIABLE_DECLARATIONS}
     var fixtureUrl = "/path/to/fixture/fixture.html";

    define(['views/home.view','jasmine','jasmine-jquery'], 
       function(HomeView,Jasmine,JasmineJQuery) {
           {CREATE OBJECTS IF NECESSARY...}

           describe('Initialize', function() {  
                 beforeEach(function(){
                      var html = jasmine.getFixtures().read(fixtureUrl);
                      jasmine.getFixtures().set(html);              
                });
               it('should check initializeView is called ', function() {
                    {YOUR_CODE_HERE...for test from the fixtures};
                    //expect($('{CONTAINER_ELEMENT_ID}').get(0)).toHaveId("{DIV_ID}");
               });  
           });                        
     });
});

I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.