Why is my variable undefined in my Jasmine testing - Jasmine.js

I started writing tests for my files js, and I get undefinedwhere I don't expect this. Here is my code:

describe('show jasmine testing', function() {
  var x;
  beforeEach(function() {
    x = 3;
  });

  describe('booleans', function() {
    it('should return true', function() {
      expect(true).toBe(true);
    });
  });

  describe('ints', function() {
    console.log('This is x: ' + x);
    expect(x).toBe(3);
  });
});

In my tests, intsmy variable is x undefined, so the test always fails. As far as I understand, this should be 3because the block beforeEachstarts before each block describe. What am I missing?

+4
source share
1 answer

You need to place the specification inside the block it. beforeEachruns for each specification. By the time the description starts, yours beforeEachmust be complete.

+4
source

Source: https://habr.com/ru/post/1525141/


All Articles