testClassNameMerging function
- @isTestGroup
- BuilderOnlyUiFactory<
UiProps> factory, - dynamic childrenFactory()
Common test for verifying that DomProps.className
s are merged/blacklisted as expected.
Typically not consumed standalone. Use commonComponentTests instead.
Related: testClassNameOverrides
Implementation
@isTestGroup
void testClassNameMerging(BuilderOnlyUiFactory factory, dynamic childrenFactory()) {
testFunction('merges classes as expected', () {
var builder = factory()
..addProp(forwardedPropBeacon, true)
..className = 'custom-class-1 blacklisted-class-1 custom-class-2 blacklisted-class-2'
..classNameBlacklist = 'blacklisted-class-1 blacklisted-class-2';
var renderedInstance = render(builder(childrenFactory()));
final forwardingTargetNodes = getForwardingTargets(renderedInstance).map(findDomNode);
expect(forwardingTargetNodes, everyElement(
allOf(
hasClasses('custom-class-1 custom-class-2'),
excludesClasses('blacklisted-class-1 blacklisted-class-2')
)
));
unmount(renderedInstance);
});
testFunction('adds custom classes to one and only one element', () {
const customClass = 'custom-class';
var renderedInstance = render(
(factory()..className = customClass)(childrenFactory())
);
var descendantsWithCustomClass = react_test_utils.scryRenderedDOMComponentsWithClass(renderedInstance, customClass);
expect(descendantsWithCustomClass, hasLength(1), reason: 'expected a single element with the forwarded custom class');
unmount(renderedInstance);
});
}