jasmine ex 2

by ronapelbaum

HTML

<script src="https://jasmine.github.io/2.4/lib/jasmine.js"></script>
<script src="https://jasmine.github.io/2.4/lib/jasmine-html.js"></script>
<script src="https://jasmine.github.io/2.4/lib/boot.js"></script>
<link rel="stylesheet" href="https://jasmine.github.io/2.4/lib/jasmine.css">

JavaScript

//--------------BL------------
var Greeter = function() {
    function greet(name) {
        if (name === "Bob") {
            return "I hate you Bob!";
        }
        return "Hello " + name;
    }
    this.greet = greet;
};

//--------------specs------------
describe('greet test suite', function() {

    var MyGreeter;
    
    beforeEach(function() {
        MyGreeter = new Greeter();
    });
    
    it('should greet corretly', function() {
        expect(MyGreeter.greet("Alice")).toBe("Hello Alice");
    });
    
    it('should greet "I hate you Bob!"', function() {
        expect(MyGreeter.greet("Bob")).toBe("I hate you Bob!");
    });
});