Socket
Book a DemoInstallSign in
Socket

test-over

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-over

run useful tests on your arrays or hashes of arrays or hashes

0.2.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Test-Over

run useful tests on your arrays or hashes of arrays or hashes

var test = require('testover');

test.max('length').over(someArray); //run your tests inline

var samelength = test.equals('length'); //or set up a testing function to call later
samelength(someArray);

Iterate over whatever property

triplets: [
    {name: 'Joe', age: 20}
 ,  {name: 'Josie', age: 20}
 ,  {name: 'Johnny', age: 20}
]

test.consistent('age').over(triplets);
test.equals('age', 20).over(triplets);

and over associative arrays

assoc_triplets: {
    first: {name: 'Joe', age: 20}
 ,  second: {name: 'Josie', age: 20}
 ,  third: {name: 'Johnny', age: 20}
}

test.consistent('age').over(assoc_triplets);
test.equals('age', 20).over(assoc_triplets);

Included tests

  • max: biggest numerical value
  • min: smallest numerical value
  • equals: if all values equal a specified value
  • consistent: if all values equal an unspecified value
  • exists: if a property exists (but might be null)
  • assigned: if a property actually exists
  • unique: if all values are unique

Add your own tests

The underlying process is essentially a fancy reduce function. With this in mind you can add your own reductions to do even more testing.

Usage

tests.add(* *<field name>, * *<reduction function>, * *<options object>)

Reduction functions

Reductions take the form r(property, row, reduced, opts) where property is the property passed to the new test row is the object or array currently being tested reduced is the variable being reduced (the variable that will be returned) opts is an object with extra goodies you can pass between iterations of your reduction

You can assign an initial value by assigning opts.init when you add the new reduction, otherwise opts.init and opts.first are assigned to the first list item's value.

Example

test.add('noConsecutiveRepeats', function(prop, row, repeats, opts) {
	var current = row[prop];
	if (current === opts.previous) {
		return false
	} else {
		opts.previous = current;
		return repeats;
	}
}, {init: true, previous: undefined});

test.noConsecutiveRepeats('property').over(array);

License

MIT

Keywords

properties

FAQs

Package last updated on 24 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.