0.4.1 • Published 9 years ago
rebem-enzyme v0.4.1
Install
npm i -D rebem-enzymeOverview
In addition to usual Enzyme methods there are few new which lets you search for components by BEM PropTypes instead of selector:
{
    block
    elem
    mods
    mix
}This object may be called bemjson.
API
:point_right: Examples below illustrates how it work with shallow wrapper just to be short – mount wrapper has absolutely the same methods.
findBEM(bemjson)
In addition to find().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block' },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
console.log(
    wrapper.findBEM({ block: 'block', elem: 'elem' }).length
);
// 1filterBEM(bemjson)
In addition to filter().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block' },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
const children = wrapper.children();
console.log(
    children.filterBEM({ block: 'block', elem: 'elem' }).length
);
// 1notBEM(bemjson)
In addition to not().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block' },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
const children = wrapper.children();
console.log(
    children.notBEM({ block: 'block', elem: 'elem' }).length
);
// 1isBEM(bemjson)
In addition to is().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block', elem: 'elem' })
);
console.log(
    wrapper.isBEM({ block: 'block', elem: 'elem' })
);
// trueclosestBEM(bemjson)
In addition to closest().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block', mods: { mod: true } },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
const firstChild = wrapper.children().first();
console.log(
    firstChild.closestBEM({ block: 'block', mods: { mod: true } }).length
);
// 1someBEM(bemjson)
In addition to some().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block' },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
const children = wrapper.children();
console.log(
    children.someBEM({ block: 'block', elem: 'elem' })
);
// trueeveryBEM(bemjson)
In addition to every().
import { BEM } from 'rebem';
import { shallow } from 'rebem-enzyme';
const wrapper = shallow(
    BEM({ block: 'block' },
        BEM({ block: 'block', elem: 'elem' }),
        BEM({ block: 'block2' })
    )
);
const children = wrapper.children();
console.log(
    children.everyBEM({ block: 'block', elem: 'elem' })
);
// false