Repository: electron/electron
File: spec/api-web-contents-spec.ts (TypeScript)

Code before:
      expect(w.webContents.isDevToolsOpened()).to.be.true();
      w.webContents.setDevToolsTitle('newTitle');
      expect(w.webContents.getDevToolsTitle()).to.equal('newTitle');
    });
  });

  describe('before-mouse-event event', () => {
    afterEach(closeAllWindows);
    it('can prevent document mouse events', async () => {
      const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
      await w.loadFile(path.join(fixturesPath, 'pages', 'mouse-events.html'));
      const mouseDown = new Promise(resolve => {
        ipcMain.once('mousedown', (event, button) => resolve(button));
      });
      w.webContents.once('before-mouse-event', (event, input) => {
        if (input.button === 'left') event.preventDefault();
      });
      w.webContents.sendInputEvent({ type: 'mouseDown', button: 'left', x: 100, y: 100 });
      w.webContents.sendInputEvent({ type: 'mouseDown', button: 'right', x: 100, y: 100 });
      expect(await mouseDown).to.equal(2); // Right button is 2
    });

    it('has the correct properties', async () => {
      const w = new BrowserWindow({ show: false });
      await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
      const testBeforeMouse = async (opts: any) => {
        const p = once(w.webContents, 'before-mouse-event');
        w.webContents.sendInputEvent({
          type: opts.type,
          button: opts.button,
          x: opts.x,
          y: opts.y,
          globalX: opts.globalX,
          globalY: opts.globalY,
          clickCount: opts.clickCount
        });
        const [, input] = await p;

        expect(input.type).to.equal(opts.type);
        expect(input.button).to.equal(opts.button);
        expect(input.x).to.equal(opts.x);
        expect(input.y).to.equal(opts.y);
        expect(input.globalX).to.equal(opts.globalX);
        expect(input.globalY).to.equal(opts.globalY);
        expect(input.clickCount).to.equal(opts.clickCount);
      };
      await testBeforeMouse({
        type: 'mouseDown',
        button: 'left',
        x: 100,
        y: 100,

Review comment (suggestion):
```suggestion
      const testBeforeMouse = async (opts: Electron.MouseInputEvent) => {
```

Code after:
      expect(w.webContents.isDevToolsOpened()).to.be.true();
      w.webContents.setDevToolsTitle('newTitle');
      expect(w.webContents.getDevToolsTitle()).to.equal('newTitle');
    });
  });

  describe('before-mouse-event event', () => {
    afterEach(closeAllWindows);
    it('can prevent document mouse events', async () => {
      const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
      await w.loadFile(path.join(fixturesPath, 'pages', 'mouse-events.html'));
      const mouseDown = new Promise(resolve => {
        ipcMain.once('mousedown', (event, button) => resolve(button));
      });
      w.webContents.once('before-mouse-event', (event, input) => {
        if (input.button === 'left') event.preventDefault();
      });
      w.webContents.sendInputEvent({ type: 'mouseDown', button: 'left', x: 100, y: 100 });
      w.webContents.sendInputEvent({ type: 'mouseDown', button: 'right', x: 100, y: 100 });
      expect(await mouseDown).to.equal(2); // Right button is 2
    });

    it('has the correct properties', async () => {
      const w = new BrowserWindow({ show: false });
      await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
      const testBeforeMouse = async (opts: Electron.MouseInputEvent) => {
        const p = once(w.webContents, 'before-mouse-event');
        w.webContents.sendInputEvent({
          type: opts.type,
          button: opts.button,
          x: opts.x,
          y: opts.y,
          globalX: opts.globalX,
          globalY: opts.globalY,
          clickCount: opts.clickCount
        });
        const [, input] = await p;

        expect(input.type).to.equal(opts.type);
        expect(input.button).to.equal(opts.button);
        expect(input.x).to.equal(opts.x);
        expect(input.y).to.equal(opts.y);
        expect(input.globalX).to.equal(opts.globalX);
        expect(input.globalY).to.equal(opts.globalY);
        expect(input.clickCount).to.equal(opts.clickCount);
      };
      await testBeforeMouse({
        type: 'mouseDown',
        button: 'left',
        x: 100,
        y: 100,