Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using 'name' as variable name produces error #142

Open
newhouse opened this issue Aug 2, 2021 · 1 comment
Open

Using 'name' as variable name produces error #142

newhouse opened this issue Aug 2, 2021 · 1 comment

Comments

@newhouse
Copy link

newhouse commented Aug 2, 2021

Something like this:

describe('a test', function ()  {
  def('name', () => 'Some Name')

  it('works', function () {
    expect($.name).to.eql('Some Name')
  })
})

Results in an error like this:

Error: Cannot create lazy variable "name" as variable with the same name exists on the provided context
    at defineGetter (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:768:13)
    at Object.onDefineVariable (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:784:7)
    at runHook (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:471:22)
    at def (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:367:9)
    at Suite.<anonymous> (/Path/to/my/project/test/server/lib/filestore.test.js:2:3)
    at SuiteTracker.execute (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:553:19)
    at SuiteTracker.trackSuite (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:538:12)
    at Suite.defineSuite (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:529:19)
    at Object.create (/Path/to/my/project/node_modules/mocha/lib/interfaces/common.js:148:19)
    at Object.only (/Path/to/my/project/node_modules/mocha/lib/interfaces/common.js:106:21)
    at context.describe.only (/Path/to/my/project/node_modules/mocha/lib/interfaces/bdd.js:69:27)
    at Function.detectSuite [as only] (/Path/to/my/project/node_modules/bdd-lazy-var/getter.js:524:25)
    at Object.<anonymous> (/Path/to/my/project/test/server/lib/filestore.test.js:1:85)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Module._compile (/Path/to/my/project/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Object.newLoader [as .js] (/Path/to/my/project/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Module.require (internal/modules/cjs/loader.js:965:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (/Path/to/my/project/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/Path/to/my/project/node_modules/mocha/lib/esm-utils.js:55:34)
    at singleRun (/Path/to/my/project/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/Path/to/my/project/node_modules/mocha/lib/cli/run.js:362:5)

I've not reproduced in a sterile environment, but I have grep'd my codebase and there is nowhere else that I def('name', ...)...and it would/should only matter if I do it in the same describe or context block anyways...

And in the spot where this is a problem, if I change the name from 'name' to anything else, it works.

@newhouse
Copy link
Author

newhouse commented Aug 2, 2021

Oh, also, I should mention that I'm using this trick to keep my code lint-free:
#56 (comment)

And if I log the value of $.name, it appears to be 'get'...so this is probably the reason. Not sure if this is a bug and/or something I can do anything about?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant