第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Enzyme、Sinon 和 ChainonChange 測試 onChange 不被調(diào)用?

使用 Enzyme、Sinon 和 ChainonChange 測試 onChange 不被調(diào)用?

jeck貓 2023-07-20 10:55:51
我正在嘗試為rc-select編寫一些測試。我想做的測試是檢查 onChange 函數(shù)是否被調(diào)用。到目前為止我所擁有的:測試組件,使用 rc-select 的樣式版本:ReactSelectTestComponent.jsximport React from 'react';import Select from '../../packages/lab/src/select/Select.jsx';const ReactSelectTestComponent = (props) => {? ? const { options } = props;? ? const onChange = (event) => {? ? ? ? if (props.onChange) {? ? ? ? ? ? props.onChange(event)? ? ? ? }? ? }? ? return (? ? ? ? <div>? ? ? ? ? ? <Select? ? ? ? ? ? ? ? name='test'? ? ? ? ? ? ? ? value='one'? ? ? ? ? ? ? ? options={options}? ? ? ? ? ? ? ? onChange={onChange}? ? ? ? ? ? />? ? ? ? </div >? ? )}export default ReactSelectTestComponent;選擇.test.js:import SelectTestComponent from './SelectTestComponent'import sinon from 'sinon';import { expect as chaiExpect } from 'chai';? // Using Expect styledescribe('Testing Select component', () => {? ? it('should call onChange', () => {? ? ? ? const onChange = sinon.spy();? ? ? ? const options =? ? ? ? ? ? [? ? ? ? ? ? ? ? { label: 'one', value: 'one' },? ? ? ? ? ? ? ? { label: 'two', value: 'two' }? ? ? ? ? ? ];? ? ? ? const wrapper = mount(<SelectTestComponent onChange={onChange} options={options} />);? ? ? ? console.log("wrapper.debug()", wrapper.debug())? ? ? ? const selectWrapper = wrapper.find('Select').first();? ? ? ? selectWrapper.simulate('change', { target: { value: "testtest" } })? ? ? ? selectWrapper.update()? ? ? ? chaiExpect(onChange.called).to.be.true;? ? });})但是,我收到此錯誤。Expected value? ?true? ? Received:? ? ? false? ??? ? Message:? ? ? expected false to be true? ? ? 38 |? ? ? ? ?selectWrapper.update()? ? ? 39 |?? ? > 40 |? ? ? ? ?chaiExpect(onChange.called).to.be.true;? ? ? ? ?|? ? ? ? ?^? ? ? 41 |? ? ?});? ? ? 42 |?? ? ? 43 |? ? ?/*? ? ? at Object.<anonymous> (tests/src/Select.test.js:40:9)我應(yīng)該在 find() 調(diào)用中使用另一個選擇器嗎?我覺得我已經(jīng)嘗試了所有的選擇。
查看完整描述

1 回答

?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個贊

工作測試:(需要通過包裝器的 props 調(diào)用 onChange。


    it("Checking if onChange prop function is called", () => {

        const onChange = sinon.spy();

        const wrapper = mount(

            <SelectTestComponent onChange={onChange} options={options} />

        );


        const func = wrapper.find("Select").props().onChange;


        console.log(wrapper.find("Select").props());

        func({ target: { value: "test" } });

        chaiExpect(onChange.called).to.be.true;

    });


查看完整回答
反對 回復(fù) 2023-07-20
  • 1 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號