Comparing version 3.0.0 to 3.0.1
@@ -46,2 +46,11 @@ class Format { | ||
get objectAsArray () { | ||
const value = Array.isArray(this.object) ? this.object | ||
: this.isArray() ? Array.from(this.object) | ||
: null | ||
Object.defineProperty(this, 'objectAsArray', { value }) | ||
return value | ||
} | ||
getId () { | ||
@@ -130,8 +139,17 @@ if (this.idMap.has(this.object)) | ||
isArray () { | ||
return Array.isArray(this.object) || this.isArguments() || ( | ||
this.object && | ||
return Array.isArray(this.object) || this.isArguments() || this.isIterable() | ||
} | ||
isIterable () { | ||
return this.object && | ||
typeof this.object === 'object' && | ||
!this.isSet() && | ||
!this.isMap() && | ||
!this.isStream() && | ||
typeof this.object[Symbol.iterator] === 'function' | ||
} | ||
isStream () { | ||
const s = this.object | ||
return s && typeof s === 'object' && ( | ||
typeof s.pipe === 'function' || // readable | ||
typeof s.write === 'function' && typeof s.end === 'function' // writable | ||
) | ||
@@ -174,3 +192,3 @@ } | ||
: this.isArray() ? this.array() | ||
// TODO buffer, error objects, JSX | ||
// TODO buffer, streams, JSX | ||
: this.pojo() | ||
@@ -259,6 +277,3 @@ | ||
arrayIsEmpty () { | ||
const obj = Array.isArray(this.object) | ||
? this.object : Array.from(this.object) | ||
return obj.length === 0 | ||
return this.objectAsArray.length === 0 | ||
} | ||
@@ -272,5 +287,3 @@ arrayEmpty () { | ||
arrayBody() { | ||
const obj = Array.isArray(this.object) | ||
? this.object : Array.from(this.object) | ||
return obj.map((val, key) => | ||
return this.objectAsArray.map((val, key) => | ||
this.arrayEntry(key, val)).join('') | ||
@@ -277,0 +290,0 @@ } |
@@ -5,8 +5,5 @@ const Same = require('./same.js') | ||
arrayBody () { | ||
const obj = Array.isArray(this.object) | ||
? this.object : Array.from(this.object) | ||
const obj = this.objectAsArray | ||
const exp = this.expectAsArray | ||
const exp = Array.isArray(this.expect) | ||
? this.expect : Array.from(this.expect) | ||
if (obj.length === exp.length) | ||
@@ -13,0 +10,0 @@ return super.arrayBody() |
@@ -22,2 +22,11 @@ const Format = require('./format.js') | ||
get expectAsArray () { | ||
const value = Array.isArray(this.expect) ? this.expect | ||
: this.isArray() ? Array.from(this.expect) | ||
: null | ||
Object.defineProperty(this, 'expectAsArray', { value }) | ||
return value | ||
} | ||
simpleMatch () { | ||
@@ -192,8 +201,5 @@ this.simple = this.test() | ||
arrayBody () { | ||
const obj = Array.isArray(this.object) | ||
? this.object : Array.from(this.object) | ||
const obj = this.objectAsArray | ||
const exp = this.expectAsArray | ||
const exp = Array.isArray(this.expect) | ||
? this.expect : Array.from(this.expect) | ||
// just need to handle extra/missing values | ||
@@ -412,4 +418,3 @@ if (obj.length === exp.length) | ||
childExpect (key) { | ||
const exp = this.isArray() && !Array.isArray(this.expect) | ||
? Array.from(this.expect) : this.expect | ||
const exp = this.expectAsArray | ||
// if we get here, we know that both expect and actual | ||
@@ -416,0 +421,0 @@ // are collections of the same type. Otherwise, they |
{ | ||
"name": "tcompare", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A comprehensive comparison library, for use in test frameworks", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38780
1121