Jasmine 2.0 SpecRunner vs Karma

Viewed 8034

I just started using Jasmine and I was able to use the SpecRunner from the Html just fine. However when I configured Karma I encountered a discrepancy:

describe('Calculator', function(){
    var obj;
    beforeEach(function(){
        //initialize object
        obj = new Object();

        this.addMatchers({
            toBeFive: function () {
                return {
                    compare: function (actual, expected) {
                        return {
                            pass: actual === 5,
                            message: actual + ' is not exactly 5'
                        }
                    }
                };
            },

This piece of code does not work from the SpecRunner.html:

 this.addMatchers({

Instead I had to use this:

 jasmine.addMatchers({

This is what is include the specrunner:

 <!-- libs... -->
  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>

  <!-- source files here... -->
  <script type="text/javascript" src="../../calculator/calculator.js"></script>

  <!-- test files here... -->
  <script type="text/javascript" src="spec/calculator/calculator-test.js"></script>

The error I get is:

TypeError: Object #<Object> has no method 'addMatchers'

Please note that Karma raise no errors but if I use jasmine.addMatchers({ it does.

3 Answers
Related