easily-expect
Advanced tools
20
index.js
@@ -39,3 +39,3 @@ 'use strict' | ||
if (typeof object[key] === 'object' && !Array.isArray(object[key])) checkObject(object[key], comparedData[key]) | ||
else if (Array.isArray(object[key])); | ||
else if (checkArray(comparedData[key], object[key])) continue | ||
else expect(`${object[key]}`).to.match(comparedData[key]) | ||
@@ -45,4 +45,22 @@ } | ||
function checkArray (comparedData, ...objects) { | ||
for (let k = objects.length; --k >= 0;) { | ||
let object = objects[k] | ||
if (Array.isArray(object)) { | ||
let j = 0 | ||
for (let i = 0, length = object.length; i < length; i++) { | ||
if (typeof object[i] === 'object' && !Array.isArray(object[i])) checkObject(object[i], comparedData[j]) | ||
else if (checkArray(comparedData[j], object[i])) continue | ||
else expect(`${object[i]}`).to.match(comparedData[j]) | ||
j = (j + 1) % comparedData.length | ||
} | ||
} else return false | ||
} | ||
return true | ||
} | ||
exports.checkArray = checkArray | ||
exports.init = data => { | ||
cacheData = data | ||
} |
{ | ||
"name": "easily-expect", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "You can easily use expect", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,5 +13,8 @@ [](https://travis-ci.org/KSH-code/easily-expect) | ||
test1: { | ||
test2: /^\d*$/ | ||
test2: /^\d*$/ | ||
}, | ||
test3: /^[a-z]{1,10}$/ | ||
test3: /^[a-z]{1,10}$/, | ||
test4: [/^[a-z]{1,10}$/, /^\d*$/, { | ||
test5: /^\d*$/ | ||
}] | ||
}) | ||
@@ -26,2 +29,7 @@ it (...) | ||
checkObject({ test1: { test2: '123123123' } }) | ||
it(...) | ||
checkObject({ test4: ['aaa', '123', { test5: '123' }, 'aaa', '123', { test5: '123' }] }) | ||
it(...) | ||
checkArray([/^\d*$/, /[a-z]{1,10}/, { test1: /^\d*$/ }], ['123', 'a', { test1: '123' }, '123','a', { test1: '123' }], ['123', 'a', { test1: '123' }]) | ||
``` | ||
@@ -32,2 +40,3 @@ ## Example | ||
* [checkEqual](https://github.com/KSH-code/easily-expect/blob/master/test/checkEqual.test.js) | ||
* [checkObject](https://github.com/KSH-code/easily-expect/blob/master/test/checkObject.test.js) | ||
* [checkObject](https://github.com/KSH-code/easily-expect/blob/master/test/checkObject.test.js) | ||
* [checkArray](https://github.com/KSH-code/easily-expect/blob/master/test/checkArray.test.js) |
@@ -10,3 +10,6 @@ /* global describe, it */ | ||
}, | ||
test3: /^[a-z]{1,10}$/ | ||
test3: /^[a-z]{1,10}$/, | ||
test4: [/^[a-z]{1,10}$/, /^\d*$/, { | ||
test5: /^\d*$/ | ||
}] | ||
}) | ||
@@ -19,3 +22,14 @@ it('Check Object in Object', () => { | ||
}) | ||
it('Check String in Object in Array', () => { | ||
checkObject({ test4: ['aaa', '123', { test5: '123' }, 'aaa', '123', { test5: '123' }] }) | ||
}) | ||
// Fail | ||
// it('Check String in Object in Array', () => { | ||
// checkObject({ test4: ['aaa', '123', { test5: '123' }, 'aaa', 'as'] }) | ||
// }) | ||
// Fail | ||
// it('Check String in Object in Array', () => { | ||
// checkObject({ test4: ['aaa', '123', { test5: '123', test6: '12433' }, 'aaa', '123', { test5: '123' }] }) | ||
// }) | ||
// Fail | ||
// it('Check String in Object', () => { | ||
@@ -22,0 +36,0 @@ // checkObject({ test4: 'abcd' }) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23832
271.45%12
20%594
412.07%39
30%