You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

jest-sorted

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-sorted - npm Package Compare versions

Comparing version

to
1.0.14

31

__tests__/index.spec.js

@@ -33,3 +33,3 @@ const { toBeSorted, toBeSortedBy } = require('../src/sorted');

expect(toBeSorted([3, 2, 1]).message()).toBe(
'Expected [3,2,1] to be sorted in ascending order'
'Expected [3,2,1] to be sorted in ascending order\nExpected 3 to be after 2'
);

@@ -50,3 +50,3 @@ });

expect(toBeSorted([1, 2, 3], { descending: true }).message()).toBe(
'Expected [1,2,3] to be sorted in descending order'
'Expected [1,2,3] to be sorted in descending order\nExpected 1 to be before 2'
);

@@ -72,3 +72,3 @@ });

expect(toBeSorted(descendingObjs, { key: 'num' }).message()).toBe(
'Expected Array(3) to be sorted by num in ascending order'
'Expected Array(3) to be sorted by num in ascending order\nExpected 3 to be after 2'
);

@@ -89,3 +89,3 @@ });

});
it('fail - { key: "missingKey", strict: "false" }: message provided for the .not casespecifies the missing key', () => {
it('fail - { key: "missingKey", strict: "false" }: message provided for the .not case specifies the missing key', () => {
expect(

@@ -113,7 +113,7 @@ toBeSorted(ascendingObjs, { key: 'missing', strict: false }).message()

const ascendingSet = new Set([5, 8, 24, 300]);
it('fail - an unsorted set no longer passes by default', () => {
it('fail: unsorted set of numbers', () => {
expect(toBeSorted(unsortedSet).pass).toBe(false);
});
it('pass - set with ascending numbers', () => {
it('pass: set with ascending numbers', () => {
expect(toBeSorted(ascendingSet).pass).toBe(true);

@@ -123,4 +123,21 @@ });

describe('non-iterables', () => {
it('fail: all non-iterables are considered unsorted', () => {
expect(toBeSorted(1).pass).toBe(false);
expect(toBeSorted(1).message()).toBe(
`1 is not iterable and cannot be sorted`
);
});
});
describe('string elements', () => {
it('fail: message surrounds string elements in double quotes', () => {
expect(toBeSorted(['5', '10']).message()).toBe(
'Expected [5,10] to be sorted in ascending order\nExpected "5" to be after "10"'
);
});
});
describe('toBeSortedBy', () => {
const ascendingObjs = [{ num: 1 }, { num: 2 }, { num: 3 }];
const ascendingObjs = [{ num: '1' }, { num: '2' }, { num: '3' }];
const descendingObjs = [{ num: 3 }, { num: 2 }, { num: 1 }];

@@ -127,0 +144,0 @@ it('extends jest.expect', () => {

{
"name": "jest-sorted",
"version": "1.0.13",
"version": "1.0.14",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,2 +12,8 @@ const defaultCompare = (a, b) => {

exports.toBeSorted = (received, options = {}) => {
if (!received[Symbol.iterator]) {
return {
pass: false,
message: () => `${received} is not iterable and cannot be sorted`,
};
}
const iterable = [...received];

@@ -26,2 +32,3 @@

let keyMsg = key ? `by ${key} ` : '';
let failingElements = '';

@@ -49,2 +56,6 @@ let pass = true;

pass = false;
const eleOrder = descending ? 'before' : 'after';
const strEle = JSON.stringify(ele);
const strNextEle = JSON.stringify(nextEle);
failingElements = `\nExpected ${strEle} to be ${eleOrder} ${strNextEle}`;
break;

@@ -55,4 +66,3 @@ }

const passMsg = pass ? 'not ' : '';
const errMsg = `Expected ${arrayMsg} to ${passMsg}be sorted ${keyMsg}in ${orderMsg} order`;
const errMsg = `Expected ${arrayMsg} to ${passMsg}be sorted ${keyMsg}in ${orderMsg} order${failingElements}`;
return {

@@ -59,0 +69,0 @@ pass,