elliotf / chai-fuzzy Goto Github PK
View Code? Open in Web Editor NEWfuzzy matchers for chai, based on underscore
License: MIT License
fuzzy matchers for chai, based on underscore
License: MIT License
Test case:
var chai = require('chai');
chai.use(require('chai-fuzzy'));
var expect = chai.expect();
function Document() {}
var actual = new Document();
actual.foo = 1;
actual.bar = 2;
var expected = { foo: 1, bar: 2};
expect(actual).to.be.jsonOf(expected);
Expected: no error.
Actual:
AssertionError: expected { Object (foo, bar, ...) } to be like JSON { Object (foo, bar, ...) }
+ expected - actual
Is this a bug? Is there a way to lossy compare just provided keys?
I had thought that this would be possible:
expect({ key1:0, key2:1 }).to.be.like({ key1:0 });
but it just seems to perform like deep.equal()
, which is already provided by Mocha. I'm confused.
Edit: the functionality that I'd expected above in my code sample is made possible with chai-like.
At the top of the index.js (line 3), chai-fuzzy checks for the presence of "require" as a function. If it is not defined, it calls it anyway (line 32).
Look into a phantomjs runner for mocha and add that to the test makefile target
underscore
is not listed on the dependencies
of chai-fuzzy, only on devDependencies
, so it fails unless underscore is added as a dependency of the parent project.
Todo: learn how hook into chai's chaining to allow something like:
expect(['a','b','c']).to.have.one.like('a');
expect({}).to.be.json.of({});
You should send a quick pull request to
https://github.com/chaijs/chai-docs/blob/master/plugins.js
so you get listed on
!!!
The current code for checking if the plugin is running in a browser or server-side only checks the types of a few different properties that are available in an application that uses require.js.
if (
typeof require === "function"
&& typeof exports === "object"
&& typeof module === "object"
) {
// server-side
_ = require('underscore');
} else {
// browser-side
_ = window._;
}
It might be better to check for the existence of the "_" property on window first, then fall back to saying it's running on the server.
My setup could be a bit different than others as well, so please let me know if you need more information.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.