How to test case for the line document.body.dispatchEvent() in react js

I want to check if document.dispatchEvent is fired when we called sendEvent method. I also want to write negative test case like when we called sendEvent method, document.body.dispatchEvent should not fire. I need some help in writing testcase.

// evt = "pageview" data={page: {name: "someName"}}
sendEvent=(evt, data)=>{
  if(document.createEvent && document.body.dispatchEvent){
    const event= document.createEvent('Event');
    event.initEvent(evt, true, true);
    event.detail = data;
    document.body.dispatchEvent(event);
  } 
}

//testcase

test("test document triggred an event", ()={
global.document.createEvent = jest.fn();
global.document.body.dispatchEvent = jest.fn();

sendEvent("pageName", {page: {name: "someName"}});
expect(global.document.body.dispatchEvent).toHaveBeenCalledWith(Event);

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>