-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): update wrapComponent to bring in usePrefix (#11575)
* feat(react): update wrapComponent to bring in usePrefix * test(react): add wrapComponent test Co-authored-by: D.A. Kahn <[email protected]>
- Loading branch information
Showing
5 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import wrapComponent from '../wrapComponent'; | ||
|
||
describe('wrapComponent', () => { | ||
it('should render the outermost element as the given type', () => { | ||
const WrappedComponent = wrapComponent({ | ||
name: 'WrappedComponent', | ||
type: 'div', | ||
}); | ||
const { container } = render(<WrappedComponent />); | ||
expect(container.firstChild.tagName).toBe('DIV'); | ||
}); | ||
|
||
it('should set the `displayName` for a component', () => { | ||
const WrappedComponent = wrapComponent({ | ||
name: 'WrappedComponent', | ||
type: 'div', | ||
}); | ||
expect(WrappedComponent.displayName).toBe('WrappedComponent'); | ||
}); | ||
|
||
it('should support static class names with `className`', () => { | ||
const WrappedComponent = wrapComponent({ | ||
name: 'WrappedComponent', | ||
type: 'div', | ||
className: 'test', | ||
}); | ||
const { container } = render(<WrappedComponent />); | ||
expect(container.firstChild).toHaveClass('test'); | ||
}); | ||
|
||
it('should support prefix class names with `className`', () => { | ||
const WrappedComponent = wrapComponent({ | ||
name: 'WrappedComponent', | ||
type: 'div', | ||
className: (prefix) => `${prefix}--test`, | ||
}); | ||
const { container } = render(<WrappedComponent />); | ||
expect(container.firstChild).toHaveClass('cds--test'); | ||
}); | ||
|
||
it('should spread additional props on the outermost node', () => { | ||
const WrappedComponent = wrapComponent({ | ||
name: 'WrappedComponent', | ||
type: 'div', | ||
}); | ||
const { container } = render(<WrappedComponent data-testid="test" />); | ||
expect(container.firstChild).toHaveAttribute('data-testid', 'test'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters