سؤال

Just curious what the function name it() stands for in the Jasmine Javascript test framework. Does it stand for something like "independent test" or something?

هل كانت مفيدة؟

المحلول

It means "it", as in the word "it". As in the test declaration reads like a sentence. You describe an object by what it does. Simple as that.

For example:

Bowling ball is round

Bowling ball has 3 holes

Might translate to a test hierarchy like this:

Bowling Ball
  it is round
  it has three holes

Which would translate to the following testing setup:

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

So because it reads well, it just becomes the way you separate individual test cases. It also encourages you to write your test description in a consistent manner because it is part of the sentence that describes the test, which makes your test suite more readable over the long term.

In the end BDD is all about readability for the test writer. So this is simply sugar.

نصائح أخرى

Nothing like that. :)

It's a block to make more readable your specs. In particular, you can write stuff like this:

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

So you're test output in the console looks like:

When the user clicks the button renders the div with class .hello
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top