W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
在給定的DOM根中查找樣式化組件的呈現(xiàn)DOM節(jié)點(diǎn)的單個(gè)實(shí)例的便捷方法。
import styled from 'styled-components'
import { find } from 'styled-components/test-utils'
const Foo = styled.div`
color: red;
`
/**
* Somewhere in your app:
*
* ReactDOM.render(
* <main>
* <Foo />
* </main>, document.body
* );
*/
// retrieves the first instance of "Foo" in the body (querySelector under the hood)
find(document.body, Foo) // HTMLDivElement | null
在給定DOM根目錄中查找樣式化組件的渲染DOM節(jié)點(diǎn)的所有實(shí)例的便捷方法。
import styled from 'styled-components'
import { findAll } from 'styled-components/test-utils'
const Foo = styled.div`
color: ${props => props.color};
`
/**
* Somewhere in your app:
*
* ReactDOM.render(
* <main>
* <Foo color="red" />
* <Foo color="green" />
* </main>, document.body
* );
*/
// retrieves a NodeList of instances of "Foo" in the body (querySelectorAll under
一種用于在酶包裝紙中查找特定樣式的組件實(shí)例的便捷方法。
import { mount } from 'enzyme'
import styled from 'styled-components'
import { enzymeFind } from 'styled-components/test-utils'
const Foo = styled.div`
color: red;
`
const wrapper = mount(
<div>
<Foo>bar</Foo>
</div>
)
enzymeFind(wrapper, Foo)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: