Comments (6)
Definitely chai makes sense as a peer dependency. Not sure jQuery does though -- it should work with pretty much any jQuery version, so there's not really anything for peer dependencies to enforce.
from chai-jquery.
https://github.com/chaijs/chai-jquery/blob/master/chai-jquery.js#L8
https://github.com/chaijs/chai-jquery/blob/master/chai-jquery.js#L16
If you need jquery to run, then jquery is a dependency. If you are using jquery as a collaborator, then is a peerDependency
In the node scenario, with your actual code:
var chai = require('chai'),
jquery = require('jquery'),
utils = {.....}
chaiJquery = require('chai-jquery')(chai, utils, jquery);
You are delegating to the node developer to install both jquery and chai (strong dependencies) in the app, and pass it to your factory. Therefore, in the internals chai-jquery is not using a jquery dependency: you do not have a require('jquery')
in your code.
IMHO, a better approach can be let jquery-chai to use the its peerDependencies (with version: "*"
for jquery) and simplify your node API to
chaiJquery = require('chai-jquery')(utils);
in your code...
module.exports = function(utils) {
return chaiJquery(require('chai'), utils, require('jquery'));
};
taking the user installed dependencies. NPM will install them if they are not present.
This is exactly the same behaviour that happens in the browser: Your code assumes jquery and chai have been included in the dom, With this approach you will have a consistent API between the 3 flavors: Node, AMD, and script, because the package manager has taken the responsibility of managing deps
With jquery as peer dependency, the user will use the same jquery version automatically in both their test (via chai-jquery) and its own code
WDYT?
from chai-jquery.
Yeah, it's true that the node API is currently a second class citizen. The standard convention for chai plugins is to export a function which can be passed to chai.use(...)
, so I'd want to keep the first and second arguments as they are now. But it sounds like peerDependencies can eliminate the last argument, which is good.
On the other hand, some people want to be able to specify the jQuery object (#36), so they can pass Ember.$
or (I imagine), zepto.
On the third hand, the wrapper hard-codes a jQuery dependency for AMD already.
So it's a bit of a mess and I'm not entirely sure what the best way of satisfying everybody is.
from chai-jquery.
There is no good solution, there is the least bad solution
The least bad solution is up to you ;)
But, now makes sense to update your dependencies?
If you are not going to require
nothing in the node side, makes no sense to have *dependencies
in the package.json. But if you are going to add require
... please, make it as a peerDependencies
from chai-jquery.
I have a situation where I also would like to specify the jQuery object -- I'm juggling between a parent and a child iframe and there is a strong possibility of 2 different jQuery objects - and instanceo
f hard codes the object to only one jQuery function.
from chai-jquery.
The pull request #66 I just made fixes issues with instanceof checks. It's still backward compatible, but I would like to get rid of the magic for good.
from chai-jquery.
Related Issues (20)
- to.have.focus is not present in latest npm release (2.0.0) HOT 2
- NPM package is outdated HOT 1
- Update Usage section in README to reflect module usage
- Assert on the DOM node tag name HOT 1
- Error: Cannot find module 'chai-jquery' HOT 1
- What does the `is.selected` assertion refer to? HOT 2
- Improve assertion message for data() chainer
- `to.have.text` assertion needs a better error message for nested elements HOT 2
- have(selector) throwing TypeError (object is not a function) HOT 8
- .to.have.text() and friends should report actual text HOT 2
- Proposal: remove be matcher, rename have matcher HOT 1
- bower.json HOT 6
- overriding obj instanceof $ HOT 1
- Cannot use exist() as a function HOT 1
- Potential failure message improvement HOT 1
- css() method won't take hex
- doesn't work unless you include it after jquery HOT 4
- assertion for :focus HOT 10
- Publish version with #73 to npm HOT 3
- Only first element is tested
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-jquery.