New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chai-subset-in-order

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-subset-in-order - npm Package Compare versions

Comparing version 1.3.0 to 2.0.0

lib/matchArray.js

8

lib/chai-subset-in-order.js
(function() {
const matchArray = require('./matchArray');
(function(chaiSubset) {

@@ -49,8 +50,3 @@ if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {

}
var aa = Array.prototype.slice.call(actual);
return expected.every(function (exp) {
return aa.some(function (act) {
return compare(exp, act);
});
});
return matchArray(expected, actual, compare);
}

@@ -57,0 +53,0 @@

{
"name": "chai-subset-in-order",
"version": "1.3.0",
"version": "2.0.0",
"description": "Chai plugin to test matching subsets in the same order",
"main": "lib/chai-subset-in-order.js",
"scripts": {
"lint": "eslint lib test",
"test": "istanbul cover _mocha",
"test-only-mocha": "mocha --recursive test",
"coveralls": "cat ./coverage/lcov.info | coveralls"

@@ -27,7 +29,10 @@ },

"devDependencies": {
"chai": "3.5.0",
"coveralls": "2.11.14",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/npm": "^7.1.0",
"chai": "4.2.0",
"coveralls": "3.0.9",
"istanbul": "0.4.5",
"mocha": "3.1.0",
"mocha-eslint": "3.0.1"
"mocha": "7.0.1",
"mocha-eslint": "6.0.0"
},

@@ -34,0 +39,0 @@ "files": [

@@ -0,3 +1,8 @@

[![NPM status](https://nodei.co/npm/chai-subset-in-order.png?downloads=true&stars=true)](https://npmjs.org/package/chai-subset-in-order)
"containSubsetInOrder" object properties matcher for [Chai](http://chaijs.com/) assertion library
It works in similar way as [chai-subset](https://www.npmjs.com/package/chai-subset).
However in arrays it must be the same order to pass an assertion.
Installation

@@ -11,66 +16,17 @@ ===========

common.js
```js
var chai = require('chai');
var chaiSubset = require('chai-subset-in-order');
chai.use(chaiSubset);
```
const chai = require('chai');
const chaiSubsetInOrder = require('chai-subset-in-order');
in your spec.js
```js
var obj = {
a: 'b',
c: 'd',
e: {
foo: 'bar',
baz: {
qux: 'quux'
}
}
};
expect(obj).to.containSubsetInOrder({
a: 'b',
e: {
baz: {
qux: 'quux'
}
}
});
//or with 'not'
expect(obj).to.not.containSubsetInOrder({
g: 'whatever'
});
```
chai.use(chaiSubsetInOrder);
const expect = chai.expect;
Also works good with arrays and `should` interface
```js
var list = [{a: 'a', b: 'b'}, {v: 'f', d: {z: 'g'}}];
list.should.containSubsetInOrder([{a:'a'}]); //Assertion error is not thrown
list.should.containSubsetInOrder([{a:'a', b: 'b'}]); //Assertion error is not thrown
list.should.containSubsetInOrder([{a:'a', b: 'bd'}]);
/*throws
AssertionError: expected
[
{
"a": "a",
"b": "b"
},
{
"v": "f",
"d": {
"z": "g"
}
}
]
to contain subset
[ { a: 'a', b: 'bd' } ]
*/
expect({ foo: 2, bar: 3 }).to.containSubsetInOrder({ foo: 2 });
expect({ foo: 2, bar: 3 }).to.containSubsetInOrder({ bar: 3 });
expect({ foo: 2, bar: 3 }).to.containSubsetInOrder({ foo:2, bar: 3 });
expect({ foo: 2, bar: 3 }).to.not.containSubsetInOrder({ foo: 5 });
expect([{ foo: 123, bar: 456 }, { baz: 111 }]).to.containSubsetInOrder([{ foo: 123 }]);
expect([{ foo: 123, bar: 456 }, { baz: 111 }]).to.containSubsetInOrder([{ bar: 456 }]);
expect([{ foo: 123, bar: 456 }, { baz: 111 }]).to.containSubsetInOrder([{ foo: 123 }, { baz: 111 }]);
expect([{ foo: 123, bar: 456 }, { baz: 111 }]).to.not.containSubsetInOrder([{ baz: 111 }, { foo: 123 }]);
```
and with `assert` interface
```js
assert.containSubsetInOrder({a: 1, b: 2}, {a: 1});
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc