enzymejs/chai-enzyme

Linking master branch for local development

Opened this issue · 6 comments

Hi all,

I was interesting in taking a look at this library to see how it works and if I was able to help contribute, so I decided to pull it down and link my codebase to use the local version of chai-enzyme.

> git clone git@github.com:producthunt/chai-enzyme.git
> cd chai-enzyme
> npm link
> cd ../my-codebase
> npm link chai-enzyme

After doing this and running my test suite, every single test that uses chai-enzyme assertions fails.

TypeError: Cannot read property 'tagName' of undefined
TypeError: Cannot read property 'className' of undefined
TypeError: Cannot read property 'prop' of undefined

And so on. It looks like wrapper is undefined in assertions/tagName.js, assertions/className.js, assertions/generic.js, etc. After unlinking and pulling the latest version down from npm, these failures go away.

So I guess my question is, am I doing something wrong here? Why do my tests fail when I link to chai-enzyme from a local folder?

You can't simply link anything that has a build process. You'll need to run npm install and npm run build inside the project folder before it can be used.

Running npm link will automatically run npm prepublish, which includes the install and build process.

mparker:~/Documents/Dev/chai-enzyme (master) $ npm link

> chai-enzyme@0.5.1 prepublish /Users/mparker/Documents/Dev/chai-enzyme
> npm run clean && npm run build


> chai-enzyme@0.5.1 clean /Users/mparker/Documents/Dev/chai-enzyme
> rimraf build


> chai-enzyme@0.5.1 build /Users/mparker/Documents/Dev/chai-enzyme
> babel src --out-dir build

However, that won't install dev dependencies - but sure, if you already have them installed you'll be all set.

Is there anything about your test suite that might be transpiling things in node_modules for you?

My test suite (mocha) uses babel-register. I thought that only transpiled my test files. Does that affect node_modules too?

Yes, babel-register affects everything that uses require.

Okay, but I still don't understand why this would affect local development. babel-register seems to not be an issue when I'm pulling this down as a devDependency from npm.