stalniy / bdd-lazy-var

Provides UI for testing frameworks such as mocha, jasmine and jest which allows to define lazy variables and subjects.
MIT License
162 stars 14 forks source link

Variables not cached #73

Closed jack-u6 closed 4 years ago

jack-u6 commented 4 years ago

It seems the variables are not cached when access in multiple places. From what I understand, they are supposed to be evaluated once on first access and cached if not overridden. Example:

import { def, get as $ } from 'bdd-lazy-var/getter';
import { describe, it, before, after, beforeEach, afterEach } from 'mocha';

describe('Foo', () => {
  def('myVar', () => Math.random());

  it('bar', () => {
    console.log($.myVar);
  })

  it('bar', () => {
    console.log($.myVar);
  })
});

Output:

      Foo
0.1305908169933785
        ✓ bar
0.7144595418228867
        ✓ bar
stalniy commented 4 years ago

Variables are cached per test. They are auto cleaned up after each test.

this is by design. There is no need to cache them forever

jack-u6 commented 4 years ago

Ah yes that makes sense, for some reason, I thought they were cached for the entirety of their scope. Just tried the same example in Rspec, it is the same behaviour. Thanks!

stalniy commented 4 years ago

Cool, so close as there is no action items from my side