#What is Jasmine?
My talk is about showing the basic similarities between Jasmine and Rpsec. The best way to learn a new concept is to relate to existing knowledge.
Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM.
def hello_world
"Hello World!"
end
describe "#hello_world" do
it "should return hello world" do
expect(hello_world).to eq("hello world")
end
endfunction helloWorld() {
return "Hello world!";
}
describe("Hello world", function() {
it("says hello", function() {
expect(helloWorld()).toEqual("Hello world!");
});
});Features of Jasmine Test
The main container is called a suite. An example of a suite is the describe("Hello world"... see above. Inside the suite are one or many anonymous it() blocks.
Matchers Types of Matchers
-
toBeNull()
-
toBeDefined();
-
toEqual(y);
To find the inverse all you need is to append .not after the expect.
Before and After Each Jasmine also includes beforeEach() and afterEach()
The cool difference- Spies In Jasmine, a spy does pretty much what it says: it lets you spy on pieces of your program (and in general, the pieces that aren't just variable checks).
For example:
var Person = function() {};
Person.prototype.helloSomeone = function(toGreet) {
return this.sayHello() + " " + toGreet;
};
Person.prototype.sayHello = function() {
return "Hello";
};
describe("Person", function() {
it("calls the sayHello() function", function() {
var fakePerson = new Person();
spyOn(fakePerson, "sayHello");
fakePerson.helloSomeone("world");
expect(fakePerson.sayHello).toHaveBeenCalled();
});
});Resources: