How to use the @jupyterlab/testutils.testEmission function in @jupyterlab/testutils

To help you get started, we’ve selected a few @jupyterlab/testutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / tests / test-docmanager / src / savehandler.spec.ts View on Github external
it('should continue to save', async () => {
        let called = 0;
        // Lower the duration multiplier.
        (handler as any)._multiplier = 1;
        let promise = testEmission(context.fileChanged, {
          test: () => {
            if (called === 0) {
              context.model.fromString('bar');
              called++;
            }
            return called === 1;
          }
        });
        context.model.fromString('foo');
        expect(handler.isActive).to.equal(false);
        handler.saveInterval = 1;
        handler.start();
        return promise;
      });
github jupyterlab / jupyterlab / tests / test-services / src / utils.spec.ts View on Github external
it('should reject if the test throws an error', async () => {
      const owner = {};
      const x = new Signal<{}, number>(owner);
      const emission = testEmission(x, {
        find: (a, b) => b === 1,
        test: (a, b) => {
          throw new Error('my error');
        },
        value: 'done'
      });
      x.emit(0);
      expect(await isFulfilled(emission)).to.equal(false);
      x.emit(1);
      await expectFailure(emission, 'my error');
    });
github jupyterlab / jupyterlab / tests / test-services / src / session / manager.spec.ts View on Github external
it('should be emitted when the running sessions changed', async () => {
        let promise = testEmission(manager.runningChanged, {
          test: (sender, args) => {
            expect(sender).to.equal(manager);
            expect(toArray(args).length).to.be.greaterThan(0);
          }
        });
        await startNew(manager);
        await promise;
      });
github jupyterlab / jupyterlab / tests / test-services / src / session / isession.spec.ts View on Github external
it('should be emitted for an unhandled message', async () => {
        const tester = new SessionTester();
        const session = await tester.startSession();
        await session.kernel.ready;
        const msgId = UUID.uuid4();
        const emission = testEmission(session.unhandledMessage, {
          find: (k, msg) => msg.header.msg_id === msgId
        });
        const msg = KernelMessage.createMessage({
          msgType: 'kernel_info_request',
          channel: 'shell',
          session: tester.serverSessionId,
          msgId,
          content: {}
        });
        msg.parent_header = { session: session.kernel.clientId };
        tester.send(msg);
        await emission;
        await tester.shutdown();
        tester.dispose();
      });
    });
github jupyterlab / jupyterlab / tests / test-docregistry / src / mimedocument.spec.ts View on Github external
it('should change the document contents', async () => {
        RENDERMIME.addFactory(fooFactory);
        await dContext.initialize(true);
        const emission = testEmission(dContext.model.contentChanged, {
          test: () => {
            expect(dContext.model.toString()).to.equal('bar');
          }
        });
        const renderer = RENDERMIME.createRenderer('text/foo');
        const widget = new LogRenderer({
          context: dContext,
          renderer,
          mimeType: 'text/foo',
          renderTimeout: 1000,
          dataType: 'string'
        });
        await widget.ready;
        await emission;
      });
    });
github jupyterlab / jupyterlab / tests / test-services / src / terminal / manager.spec.ts View on Github external
it('should emit a runningChanged signal', async () => {
        session = await manager.startNew();
        const emission = testEmission(manager.runningChanged, {
          test: () => {
            expect(session.isDisposed).to.equal(false);
          }
        });
        await manager.shutdown(session.name);
        await emission;
      });
    });
github jupyterlab / jupyterlab / tests / test-services / src / kernel / ikernel.spec.ts View on Github external
it('should emit `"reconnecting"`, then `"connected"` status', async () => {
      let connectedEmission: Promise;
      const emission = testEmission(defaultKernel.statusChanged, {
        find: () => defaultKernel.status === 'reconnecting',
        test: () => {
          connectedEmission = testEmission(defaultKernel.statusChanged, {
            find: () => defaultKernel.status === 'connected'
          });
        }
      });

      await defaultKernel.reconnect();
      await emission;
      await connectedEmission;
    });
  });
github jupyterlab / jupyterlab / tests / test-services / src / utils.spec.ts View on Github external
it('should resolve to the given value', async () => {
      const owner = {};
      const x = new Signal<{}, number>(owner);
      const emission = testEmission(x, {
        value: 'done'
      });
      x.emit(0);
      expect(await emission).to.equal('done');
    });
github jupyterlab / jupyterlab / tests / test-apputils / src / widgettracker.spec.ts View on Github external
it('should not emit when a widget has been injected', async () => {
        const one = createWidget();
        const two = createWidget();
        let total = 0;
        let promise = testEmission(tracker.currentChanged, {
          find: () => {
            return total === 1;
          }
        });

        tracker.widgetAdded.connect(() => {
          total++;
        });
        void tracker.add(one);
        void tracker.inject(two);
        Widget.attach(two, document.body);
        focus(two);
        Widget.detach(two);
        await promise;
        one.dispose();
        two.dispose();
github jupyterlab / jupyterlab / tests / test-services / src / kernel / ikernel.spec.ts View on Github external
test: () => {
          connectedEmission = testEmission(defaultKernel.statusChanged, {
            find: () => defaultKernel.status === 'connected'
          });
        }
      });