Why is my variable undefined in my Jasmine test - Jasmine.js
jasmine, javascript
Solution
You need to put the spec inside an `it` block. `beforeEach` is run for each spec. By the time the describe has run, your `beforeEach` has yet to be executed.
Problem
I have started writing tests for my `js` files and I am getting an `undefined` where I don't expect it. 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 `ints` tests, my `x` variable is `undefined`, so the test always fails. From what I understand it should be `3` because the `beforeEach` block is run before each `describe` block. What is it that I am missing?