ibolmo / jasmine-jstd-adapter

(unsupported) Jasmine JsTestDriver Adapter. Write Jasmine BDD code, and run it on JsTD.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Work in describe is not executed properly

mhevery opened this issue · comments

here is the bug


describe('bug', function(){
  var state = 'initial';

  it('should have state initial', function(){
    expect(state).toEqual('initial');
    state = 'asserted';
  });

  it('should have state reset to initial', function(){
    expect(state).toEqual('initial'); // this FAILS
    state = 'asserted';
  });
});

The fail is expected, since state is set to 'asserted' after the first expect. I don't believe that you'd get 'initial' if you had used jasmine stand alone. The reason being of the JavaScript closure -- e.g. the state is accessible read/write by both it calls. Please double check me.

You could try:
describe('bug', function(){
var state;

  beforeEach(function(){
    state = 'initial';
  });

  it('should have state initial', function(){
    expect(state).toEqual('initial');
    state = 'asserted';
  });

  it('should have state reset to initial', function(){
    expect(state).toEqual('initial'); // should now work
    state = 'asserted';
  });
});