What does “this ()” mean in Jasmine?

Just curious what the name of the it () function means in the Jasmine Javascript test environment. Does this mean something like an "independent test" or something else?

+7
javascript jasmine bdd
source share
2 answers

It means "this," as in the word "this." As in the test declaration, it is read as a sentence. You describe object that it does. Just like that.

For example:

Bowling ball round

Bowling ball has 3 holes

Transfer to the test hierarchy as follows:

 Bowling Ball it is round it has three holes 

To switch to the following test setup:

 describe(BowlingBall, function() { it('is round', function() {}); it('has three holes', function() {}); }); 

Since it reads well, it just becomes how you separate individual test cases. He also encourages you to write a test description so that it is part of a sentence that describes the test, which makes your test suite more readable in the long run.

After all, BDD is all about readability for the author of the test. So it's just sugar.

+12
source share

Nothing like this.:)

This is a block to make your specifications more readable. In particular, you can write the following:

 describe("When the user clicks the button", function() { it("renders the div with class .hello", function() { // your assertion here }); }); 

So, you are the test output in the console:

 When the user clicks the button renders the div with class .hello 
0
source share

All Articles