Requerio: predictable client-side state + server-side testability
npm install requerio[![Known Vulnerabilities][snyk-image]][snyk-url]
[![Linux Build Status][linux-image]][linux-url]
[![Mac Build Status][mac-image]][mac-url]
[![Windows Build Status][windows-image]][windows-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![License][license-image]][license-url]
While Requerio was named with Cheerio in mind, Cheerio is no longer recommended
for server-side tests. Server-side tests should use jQuery with
JSDOM, or any
other DOM emulator.
#### Install:
``shell`
npm install requerio redux jquery jsdom
#### Declare $:
`javascript`
const {JSDOM} = require('jsdom');
const html = fs.readFileSync('./index.html'), 'utf8');
const {window} = new JSDOM(html);
global.window = window;
global.document = window.document;
const $ = global.$ = require('jquery');
##### - or -
`html`
#### Declare Redux:
`javascript`
const Redux = global.Redux = require('redux');
##### - or -
`html`
#### Declare Requerio:
`javascript`
const Requerio = require('requerio');
##### - or -
`html`
#### Declare $organisms:
At declaration, organisms are just empty namespaces.
`javascript`
const $organisms = {
'#yoda': null,
'.midi-chlorian': null
};
#### Instantiate requerio:
`javascript`
const requerio = window.requerio = new Requerio($, Redux, $organisms);
#### Initialize requerio:
`javascript`
requerio.init();
#### Use:
`javascript$organisms['#yoda']
// During initialization, the null underwentrequerio.$orgs['#yoda']
// inception into Requerio organism . This.midi-chlorian
// organism has properties, methods, and state. It is home to the
// organisms. (A productive biome would want them to#yoda
// be symbionts and not parasites!) To demonstrate that iscss
// alive and stateful, let's dispatch a action to give it acolor:green
// css property.
requerio.$orgs['#yoda'].dispatchAction('css', {color: 'green'});
// This action will turn the organism's text green in the browser.
// We can observe its state after dispatching the action.
const mainState = requerio.$orgs['#main'].getState();
// In Node, we can test to ensure the action updated the state correctly.
assert.equal(mainState.css.color, 'green');
``
* addClass
* after
* append
* attr
* before
* css
* data
* detach
* empty
* height
* html
* prepend
* prop
* remove
* removeClass
* removeData
* scrollLeft
* scrollTop
* setActiveOrganism
* setBoundingClientRect
* text
* toggleClass
* val
* width
* blur
* focus
#### See also the code examples.
[snyk-image]: https://snyk.io/test/github/electric-eloquence/requerio/master/badge.svg
[snyk-url]: https://snyk.io/test/github/electric-eloquence/requerio/master
[linux-image]: https://github.com/electric-eloquence/requerio/workflows/Linux%20build/badge.svg?branch=master
[linux-url]: https://github.com/electric-eloquence/requerio/actions?query=workflow%3A"Linux+build"
[mac-image]: https://github.com/electric-eloquence/requerio/workflows/Mac%20build/badge.svg?branch=master
[mac-url]: https://github.com/electric-eloquence/requerio/actions?query=workflow%3A"Mac+build"
[windows-image]: https://github.com/electric-eloquence/requerio/workflows/Windows%20build/badge.svg?branch=master
[windows-url]: https://github.com/electric-eloquence/requerio/actions?query=workflow%3A"Windows+build"
[coveralls-image]: https://img.shields.io/coveralls/electric-eloquence/requerio/master.svg
[coveralls-url]: https://coveralls.io/r/electric-eloquence/requerio
[license-image]: https://img.shields.io/github/license/electric-eloquence/requerio.svg
[license-url]: https://raw.githubusercontent.com/electric-eloquence/requerio/master/LICENSE