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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With