stalniy/bdd-lazy-var

Variables not cached

Closed this issue · 3 comments

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

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

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!

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