stalniy/bdd-lazy-var

Troubleshooting

Closed this issue · 6 comments

Great utility! Wish I could get it to work. Getting error:

Suite uses name variable:
     ReferenceError: $name is not defined

I pasted your exact example into my app:

import { expect } from 'chai'

describe('Suite', function() {
  def('name', function() {
    return getName();
  });

  it('uses name variable', function() {
    expect($name).to.exist
  });

  it('does not use name, so it is not created', function() {
    expect(1).to.equal(1);
  });
});

My test script is:

mocha -u bdd-lazy-var --compilers js:babel-core/register --require jsdom-global/register --require ./web/test/index.js --require ignore-styles --recursive ./web/test -R nyan

I am using mocha version 3.0.2

Your assistance is greatly appreciated!

If you want to use global vars, you need to include bdd-lazy-var/global Ui instead of bdd-lazy-var

Got it thanks (read the readme more closely - I would suggest revising the first section so that the mocha command line option matches the syntax of first example).

Now the global example runs but I am having trouble with the rspec example, any ideas?

> mocha -u bdd-lazy-var/rspec --compilers js:babel-core/register --require jsdom-global/register --require ./web/test/index.js --require ignore-styles --recursive ./web/test -R nyan

  1 failing

  1) User when is active "before each" hook for "sets isActive to true":
     ReferenceError: $user is not defined
      at Context.<anonymous> (web/test/bdd_test.js:11:22)
import { expect } from 'chai'

describe('User', function() {
  subject(() => new User($attrs))

  describe('when is active', function() {
    def('attrs', () => {
      return { isActive: true }
    })

    beforeEach(() => $user.save())

    it('sets isActive to true', function() {
      expect($user.isActive).to.be.true
      expect(!$user.isNew).to.be.false
    })

    describe('when changed to inactive', function() {
      def('attrs', () => {
        return { isActive: false }
      })

      it('sets "isActive" to false', function() {
        expect($user.isActive).to.be.false
        expect(!$user.isNew).to.be.false
      })
    })
  })
})

NVM I believe I just didn't have your User class (although error didn't indicate that). This modified example works!

import { expect } from 'chai'

describe('Rspec', function() {
  subject(() => $attrs)

  describe('when is active', function() {
    def('attrs', () => {
      return { isActive: true }
    })

    it('sets isActive to true', function() {
      expect($subject.isActive).to.be.true
    })

    describe('when changed to inactive', function() {
      def('attrs', () => {
        return { isActive: false }
      })

      it('sets "isActive" to false', function() {
        expect($subject.isActive).to.be.false
      })
    })
  })
})

You actually had an issue not because of class but because of variable. You defined subject but didn't define user that's why JS told you that var is undefined. If you used $subject in first example instead of $user JS would complain about undefined variable/class User

Cool :) So, may I close this ticket?

Appreciate the help! I copied that code exactly from the readme so please fix it there :) And yes please close.

Done. Thanks!