Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Jasmine is called a "BDD" testing framework even if no "Given/When/Then" supported?

In the introduction of Jasmine, it says:

Jasmine is a behavior-driven development framework for testing JavaScript code.

I read several articles of BDD, and seems we should use 'Given/When/Then' to define "Scenario"s, which is what "cucumber" does. But in Jasmine, I can't see any of such methods.

Can we still call Jasmine a "BDD" testing framework even if it doesn't have such concept?

like image 905
Freewind Avatar asked Nov 29 '15 14:11

Freewind


People also ask

Why is Jasmine a BDD?

The current home page of Jasmine says that it's “a behavior-driven development framework for testing JavaScript code.” So the intent of Jasmine is to be a BDD testing framework, per its authors. So, while the authors of Jasmine have intended it as a BDD testing framework, it can also be used with TDD and unit testing.

Why is BDD preferred over other frameworks?

BDD provides a path that acts as a bridge to overcome the gap between the technical and the non-technical teams because the test cases are commonly written in simple text, i.e. English. The main advantage of BDD is the low jargon and clearer approach which is easier to understand.

Is Jasmine a testing framework?

Jasmine is a framework for unit testing JavaScript. It's open source and has more than 15,000 stars on GitHub at the time of this writing. Its popularity among developers means that it has a strong community and documentation available when you get stuck.


1 Answers

Jasmine does not prevent you from using given-when-then, below is an example showing two ways you could use given-when-then whilst using Jasmine.

describe("Given a string containing 'foo'", function(){
    var someString;
    beforeEach(function() {
        someString = "foo";
    });
    describe("When I append 'bar'", function(){
        beforeEach(function() {
            someString += "bar";
        });
        it("Then the string is 'foobar'", function(){
            expect(someString).toBe("foobar");
        });
    });
    it("When I append 'baz' Then the string is 'foobaz'", function(){
        someString += "baz";
        expect(someString).toBe("foobaz");
    });
});

Find a style that works for you. You should ensure that the test description describes effectively what you are testing. You can use the given-when-then style sentence as a tool to ensure that your test description is precise about what is being tested.

like image 60
areve Avatar answered Oct 03 '22 14:10

areve