Jasmine cheat sheet - async specs

Demonstrating Jasmine async specs

HTML

<script src="http://jasmine.github.io/1.3/lib/jasmine.js"></script>
<script src="http://jasmine.github.io/1.3/lib/jasmine-html.js"></script>
<link rel="stylesheet" href="http://jasmine.github.io/1.3/lib/jasmine.css">
<script src="http://code.angularjs.org/1.1.0/angular-mocks.js"></script>

JavaScript

var app = angular.module('appointments', []);

app.service('flash', function(){
    this.msg = function(msg){
        console.log(msg);
    }
});
app.controller('new', function ($scope, Appointment, flash) {
    $scope.appointment = new Appointment();
    $scope.attachments = [];
    $scope.appointment.agendas_attributes = [];
    
    $scope.createAppointment = function(){
    
        $scope.appointment.attachments = $scope.attachments;
    
        $scope.appointment.create().then(function(data){
          flash.msg(data.message);
        }, function(error){
          flash.msg('error', error.data.message);
          $scope.appointment.$errors = error.data.errors;
        });
    
    };

})

describe("Appointment new controller", function () {
    var $scope, controller, mockAppointment, mockFlash, newCtrl;


    beforeEach(function () {

        module("appointments");

        inject(function (_$rootScope_, $controller) {
            $scope = _$rootScope_.$new();
            console.log(jasmine.createSpyObj);
            $controller("new", {
                $scope: $scope,
                Appointment: function() {
                    return jasmine.createSpyObj("Appointment", ["create"])
                }
            });

        });

    });
    it("test", function(){
        $scope.createAppointment();
    })
});
    
    
// 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);
    };

    console.log("executre:")
    execJasmine();
    function execJasmine() {
        jasmineEnv.execute();
        trivialReporter.outerDiv.className += ' show-passed';
    }

})();