mardi 5 septembre 2017

Creating DOM elements for javascript testing

So i have a particular problem, inside my react component i used commands like these:

document.getElementById('modalsContainer').appendChild(recognitionProfileZoom);
document.getElementById('modalsContainer').appendChild(categoryZoom);

and:

document.getElementById('cddoccategoryzoom').value;

But these elements that were specified by ID don't exist in my component.
How would one go about creating these objects on the tests?

The code below would use these elements but it fails because they don't exist(the hideModal function utilizes the document.append from before)

describe("CaptureProfileModal functions tests", function() {

it('Should hide the modal', function() {
    var wrapper, instance;

    wrapper = mount(
        <CaptureProfileModal
            gridAction={1}
            captureSettingCode={15}
            fields={mockedFields}/>
    );

    wrapper.setState({
        showModal: true
    });

    instance = wrapper.component.getInstance();
    instance.hideModal();
});

Aucun commentaire:

Enregistrer un commentaire