reBEM addons for React Test Utilities.
npm i -D rebem-test-utils
In addition to usual React Test Utilities methods there are few new which lets you search for components by BEM PropTypes:
{
block
elem
mods
mix
}
This object may be called bemjson
.
In addition to isCompositeComponentWithType()
.
import { BEM } from 'rebem';
import TestUtils from 'rebem-test-utils';
const tree = TestUtils.renderIntoDocument(
BEM({ block: 'block' },
BEM({ block: 'block', elem: 'elem' })
)
);
const elem = TestUtils.findRenderedDOMComponentWithClass(tree, 'block__elem');
console.log(
TestUtils.isCompositeComponentWithBEM(elem, { block: 'block', elem: 'elem' })
);
// true
In addition to scryRenderedDOMComponentsWithClass()
.
import { BEM } from 'rebem';
import TestUtils from 'rebem-test-utils';
const tree = TestUtils.renderIntoDocument(
BEM({ block: 'block' },
BEM({ block: 'block', elem: 'elem' }),
BEM({ block: 'block', elem: 'elem' })
)
);
const elems = TestUtils.scryRenderedDOMComponentsWithBEM(tree, { block: 'block', elem: 'elem' });
console.log(elems.length);
// 2
console.log(
elems.every(elem => TestUtils.isDOMComponent(elem))
);
// true
In addition to findRenderedDOMComponentWithClass()
.
import { BEM } from 'rebem';
import TestUtils from 'rebem-test-utils';
const tree = TestUtils.renderIntoDocument(
BEM({ block: 'block' },
BEM({ block: 'block', elem: 'elem' })
)
);
const elem = TestUtils.findRenderedDOMComponentWithBEM(tree, { block: 'block', elem: 'elem' });
console.log(
TestUtils.isDOMComponent(elem)
);
// true