201-created / ember-cli-acceptance-test-helpers

A set of useful test helpers for ember acceptance tests.
https://www.npmjs.com/package/ember-cli-acceptance-test-helpers
MIT License
47 stars 17 forks source link

jshint should not complain after installing the addon #2

Closed bantic closed 9 years ago

bantic commented 9 years ago

as mentioned in #1

eriktrom commented 9 years ago

more context: when adding the helpers to .jshintrc inside the tests/ directory, js hint throws Redefinition of expectElement error. Removing them from .jshintrc removes this error but then you get expectElement' is not defined.

setting "undef": false fixes the problem, but is not ideal. I don't know why this happens though :)

jackmatt2 commented 9 years ago

@trombom same issue here

bantic commented 9 years ago

@trombom What file specifically is the source of the error? Can you share a gist of the file that has that redefinition error?

eriktrom commented 9 years ago

howdy, so technically the was spit out only for the following variables:

expectElement
expectNoElement
expectComponent

saying they we're trying to be redefined, on the following lines within your library: https://github.com/201-created/ember-cli-acceptance-test-helpers/blob/877a704899f720b7eb75b71d3dbc9b8b5be0d198/test-support/helpers/201-created/sync.js#L7-L9

That, however is not actually true, thus the error is odd.

Here is the rundown of what happens:

When adding the variables to .jshint inside the test directory, it says your trying to redefine them. If you don't add them though, then when you use the variable in your tests, you get an error for an undefined global variable. Even more odd and worth noting is that the js hint website says that a redefinition error is only thrown when trying to redefine a variable that is a built-in native object. See https://jslinterrors.com/redefinition-of-a

Thus, adding the three variables to .jshint seems to throw an error saying your trying to redefine a built in native object, yet the native object is not known to chrome, so either something in the es6-module transpiler or something within ember-cli is mucking with something that I have no context around. i wonder if this has been an issue for anyone else.

One way to fix the problem is to assign those vars as properties, then export the object, which i tried and it worked. Using another syntax though like export var theFnYouCallToDefineTheVar() doesn't work either. Perhaps the fact that your assigning an exported var to the result of a function is the problem, though that's just speculation.

of course there is always a chance I'm an idiot but I played with it a bit yesterday, so I don't think that's the case

to reproduce it, make a new ember app, install your lib, then try it out. This error is not thrown when running the tests within your addon, so it's hard to see otherwise.

bantic commented 9 years ago

@trombom thanks for a very thorough explanation. I can repro this, now. I'll take a look at it later today.

bantic commented 9 years ago

As a workaround for the moment, you could skip adding the helpers to tests/.jshintrc altogether and refer to them this way:

App.testHelpers.expectElement etc

bantic commented 9 years ago

@trombom @jackmatt2 thanks for reporting. Version 0.2.2 should fix this. You should be able to fix by:

jackmatt2 commented 9 years ago

@bantic I was just reading you workaround as you message popped up, haha.

eriktrom commented 9 years ago

:+1:

haha, ditto.