An open API service indexing awesome lists of open source software.

https://github.com/ryanve/aok

Simple JavaScript test suite API
https://github.com/ryanve/aok

Last synced: about 1 year ago
JSON representation

Simple JavaScript test suite API

Awesome Lists containing this project

README

          

# [aok](../../)

#### Extensible JavaScript test suite [module](https://npmjs.org/package/aok)

- [API](#api)
- [grunt aok](#grunt-aok)
- [Resources](#resources)
- [Developers](#developers)
- [Fund](#fund)
- [License](#license)


## API ([1.9](../../releases))

- [aok()](#aok-function)
- [Console methods](#console-methods)
- [Utilities](#utilities)


### aok() → `aok` instance
#### Syntaxes

- [`aok(object)`](#verbose-syntax)
- [`aok(test)`](#anonymous-syntax)
- [`aok(id, test)`](#pair-syntax)
- [`aok()`](#idle-syntax)

#### Properties
- **id**: identifier or name for the test (defaults to a positive integer)
- **test**: result or callback (called in the instance's scope)
- **pass**: message or callback (default: "ok")
- **fail**: message or callback (default: "FAIL")
- **handler**: defaults to `aok.prototype.handler`
- **express**: defaults to `aok.prototype.express`
- **explain**: defaults to `aok.prototype.explain`
- **run**: defaults to `aok.prototype.run`
- **cull**: defaults to `aok.prototype.cull`
- **init**: defaults to `aok.prototype.init`

#### Verbose syntax
##### `aok(object)`

```js
aok({
id: 'example',
test: function() {
return 'example' === this.id;
}
});
```

#### Anonymous syntax
##### `aok(test)` for non-object tests

```js
aok(true);
aok(aok instanceof aok);
aok(function() {
return isFinite(this.id);
});
```

#### Pair syntax
##### `aok(id, test)` [1.8+](../../issues/1)

```js
aok('example', true);
aok('example', function() {
return true;
});
```

#### Idle syntax
##### Calling `aok()` without arguments creates an idle instance that can manually be run later.

```js
var o = aok();
o.test = true;
o.run();
```

### Console methods
#### uses [native `console`](https://developers.google.com/chrome-developer-tools/docs/console-api) where available

- `aok.log(message)`
- `aok.info(message)`
- `aok.warn(message)`
- `aok.error(message)`
- `aok.assert(expression, message)` 1.6+
- `aok.trace()`
- `aok.clear()` 1.7+

### Utilities

#### aok.can(fn)
- Get a new function that uses `try`/`catch` to test if fn can run.
- ⇒ Function (⇒ boolean)

#### aok.pass(stack, fn, scope?, limit?)
- Iterate stack to count passes until limit. ([example](../../commit/5e9273f34bc113bd540534a137fce1302bdb4db4#commitcomment-4498304))
- ⇒ number

#### aok.fail(stack, fn, scope?, limit?)
- Iterate stack to count fails until limit. ([example](../../commit/5e9273f34bc113bd540534a137fce1302bdb4db4#commitcomment-4498304))
- ⇒ number

#### aok.perform(trials, fn)
- Test how many milliseconds it takes fn to run trials times.
- ⇒ number

#### aok.race(trials, rivals)
- Test how many milliseconds it takes each rival to run trials times.
- ⇒ Array

#### aok.result(object, key|fn)
- Get `object[key]` or its method's result if callable.
- ⇒ *

#### aok.explain(item?)
- Represent item (or self) as a string.
- ⇒ string

***

## grunt aok
#### aok 1.5+ includes a simple grunt [task](./tasks) for running tests via [grunt](http://gruntjs.com/)
##### Configure files to [require](http://nodejs.org/api/globals.html#globals_require)

```js
grunt.initConfig({
aok: {
test: ['./test/'],
extras: ['./test/extras']
}
});
```

##### Load task `'aok'`
```js
grunt.loadNpmTasks('aok');
```

##### Run `'aok'` tasks

```sh
$ grunt aok
$ grunt aok:test
$ grunt aok:extras
```
## Resources
- See a [universal GruntFile](https://github.com/ryanve/universal/blob/master/GruntFile.js) and [test dir](https://github.com/ryanve/universal/tree/master/test) for a solid setup
- See test dirs in [ryanve packages](https://npmjs.org/~ryanve) for examples

## Developers
#### Contribute edits to [`/src`](./src) or report [issues](../../issues)

```sh
$ npm install # install dependencies
$ grunt jshint:sub # lint sub dirs
$ grunt aok # run tests
```

Builds have +timestamp in the [version](http://semver.org/) number and are made later via `grunt`.

## Fund

[Tip the developer](https://www.gittip.com/ryanve/) =)

## License

[MIT](package.json)