私は私のCheckboxWidget
コンポーネントでantd Checkbox
コンポーネントを使用していますを持っているコンポーネント、コンポーネントhas a contextType
defined:テストその子コンテキスト
static contextTypes: {
checkboxGroup: any
}
私はそれが酵素でレンダリングshallow
を使ってテストしたいと思いますので、私が使用していますbeforeEach
ブロック内recompose
からwithContext
ヘルパー:
describe('Simple Checkbox Widget',() => {
beforeEach(() => {
withContext({
getChildContext: function() {
return {checkboxGroup: null}
},
childContextTypes: {
checkboxGroup: shape({
disabled: bool,
toggleOption: func,
value: array
})
}
})(CheckboxWidget)
})
})
しかし、私はこのような私のテストを記述します。
it('renders a checkbox from Antd',() => {
const wrapper = shallow(<Subject />)
const actual = wrapper.find(AntdCheckbox).length
const expected = 1
expect(actual).toEqual(expected)
})
Checkbox
ウィジェットが見つからないため、テストに失敗していることがわかりました。私はwrapper.instance()
がSubject
とwrapper.instance().children
が未定義であることがわかっ
<Subject />
:私は次のようにレンダリングされたコンポーネントが見えますので、それはあると思います。 wrapper.dive
を使用しようとしましたが、wrapper.instance()
でも動作していないようです。
私は 'shallowOptionsは、あなたが提供されるオプションであることと、'浅い( 、shallowOptions)に ''マウント( 、mountOptions)を使用して、私のテストを変換します。ありがとうございました –
vamsiampolu