How to set the width of a React component during test?

前端 未结 3 2022
隐瞒了意图╮
隐瞒了意图╮ 2021-02-19 05:23

I\'m trying to test a slider component. \"\"

This slider compone

3条回答
  •  庸人自扰
    2021-02-19 05:44

    Here is an example. React 0.14 warns about rendering document into body. Like what Matt said, we will need to append 'div' in the iframe to prevent such errors.

    describe('html tooltip utility class', function() {
    
    let iframe;
    let div;
    
    beforeEach(() => {
        iframe = document.createElement('iframe');
        document.body.appendChild(iframe);
        div = document.createElement('div');
    });
    
    
    it('returns true if text overflows', () => {
        // jshint ignore:start
        let style = {
            width: 5
        };
        let data = 'hello this is a long text.';
        iframe.contentDocument.body.appendChild(div);
        ReactDOM.render(
    {data}
    , div); // jshint ignore:end let textNode = div.querySelectorAll('div')[0]; expect(HTMLTooltip.showTooltip(textNode)).to.be.true; }); afterEach(() => { document.body.removeChild(iframe); }); });

提交回复
热议问题