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.
npm install requerio redux jquery jsdom
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');
<script src="jquery.min.js"></script>
const Redux = global.Redux = require('redux');
<script src="redux.min.js"></script>
const Requerio = require('requerio');
<script src="requerio.min.js"></script>
At declaration, organisms are just empty namespaces.
const $organisms = {
'#yoda': null,
'.midi-chlorian': null
};
const requerio = window.requerio = new Requerio($, Redux, $organisms);
requerio.init();
// During initialization, the null `$organisms['#yoda']` underwent
// inception into Requerio organism `requerio.$orgs['#yoda']`. This
// organism has properties, methods, and state. It is home to the
// `.midi-chlorian` organisms. (A productive biome would want them to
// be symbionts and not parasites!) To demonstrate that `#yoda` is
// alive and stateful, let's dispatch a `css` action to give it a
// `color: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