Jasmine - checking if order of actual matters to spy expectations

checking if order of actual matters to spy expectations

by eitanp461

HTML

<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.js"></script>
<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine-html.js"></script>
<link rel="stylesheet" href="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.css">

JavaScript

describe("does order matter", function () {
    var foo;

    beforeEach(function () {
        foo = {
            bar: function (callback) {
                callback({
                    a: 'a',
                    b: 'b'
                });
            }
        };
    });

    it("expects to be called with different order of keys", function () {
        var callbackSpy = jasmine.createSpy('spy name');
        foo.bar(callbackSpy);
        expect(callbackSpy).toHaveBeenCalledWith({
                    b: 'b',
                    a: 'a'
                });
    });

    it("expects to be called with the same order of keys", function () {
        var callbackSpy = jasmine.createSpy('spy name');
        foo.bar(callbackSpy);
        expect(callbackSpy).toHaveBeenCalledWith({
                    a: 'a',
                    b: 'b'
                });
    });
});

// Jasmine spec runner
(function () {
    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.updateInterval = 1000;

    var trivialReporter = new jasmine.TrivialReporter();

    jasmineEnv.addReporter(trivialReporter);

    jasmineEnv.specFilter = function (spec) {
        return trivialReporter.specFilter(spec);
    };

    var currentWindowOnload = window.onload;

    window.onload = function () {
        if (currentWindowOnload) {
            currentWindowOnload();
        }
        execJasmine();
    };

    function execJasmine() {
        jasmineEnv.execute();
        trivialReporter.outerDiv.className += ' show-passed';
    }

})();