How to use the @aurelia/testing.createSpy function in @aurelia/testing

To help you get started, we’ve selected a few @aurelia/testing 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 aurelia / aurelia / packages / __tests__ / 2-runtime / binding.spec.ts View on Github external
xit('should unbind if it is bound', function () {
      const { sut } = createFixture();
      const scope: any = {};
      sut['$scope'] = scope;
      sut.$state = State.isBound;
      sut['targetObserver'] = {} as any;
      const unobserveSpy = createSpy(sut, 'unobserve');
      const unbindSpy = dummySourceExpression.unbind = createSpy();
      (dummySourceExpression as any).$kind |= ExpressionKind.HasUnbind;
      sut.$unbind(LF.fromUnbind);
      assert.strictEqual(sut['$scope'], undefined, `sut['$scope']`);
      assert.strictEqual(sut['$state'] & State.isBound, 0, `sut['$state'] & State.isBound`);
      // expect(unobserveSpy, `unobserveSpy`).to.have.been.calledWith(true);
      // expect(unbindSpy, `unbindSpy`).to.have.been.calledWith(LF.fromUnbind, scope, sut);
    });
  });
github aurelia / aurelia / packages / __tests__ / 1-kernel / di.spec.ts View on Github external
beforeEach(function () {
      getDesignParamtypes = createSpy(DI, 'getDesignParamtypes', true);
    });
    // eslint-disable-next-line mocha/no-hooks
github aurelia / aurelia / packages / __tests__ / router / queued-browser-history.spec.ts View on Github external
it('queues consecutive calls', async function () {
    const { sut, tearDown, callback } = setup();

    const callbackSpy = createSpy(sut, 'dequeue' as keyof typeof sut);
    sut.activate(callback);

    const length = sut.length;
    sut.pushState({}, null, '#one');
    sut.replaceState("test", null, '#two');
    sut.back();
    sut.forward();

    assert.deepStrictEqual(
      callbackSpy.calls,
      [],
      `callbackSpy.calls`,
    );

    assert.strictEqual(sut.length, length, `sut.length`);
    assert.strictEqual(sut['queue'].length, 4, `sut.queue.length`);
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / observer-locator.spec.ts View on Github external
it(_`getObserver() - throws if $observers is undefined`, function () {
    const { sut } = setup();
    const obj = {};
    const writeSpy = createSpy(Reporter, 'write');
    Reflect.defineProperty(obj, '$observers', { value: undefined });
    sut.getObserver(LF.none, obj, 'foo');

    writeSpy.restore();
    assert.deepStrictEqual(
      writeSpy.calls,
      [
        [0, {}],
      ],
      `writeSpy.calls`,
    );
  });
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / dom.spec.ts View on Github external
it('should add the specified eventListener to the node if the node is specified', function (done) {
      const node = ctx.dom.createElement('div');
      const eventListener = createSpy();
      ctx.dom.addEventListener('click', eventListener, node);
      node.dispatchEvent(new ctx.CustomEvent('click', { bubbles: true }));

      setTimeout(
        () => {
          assert.strictEqual(eventListener.calls.length, 1, `eventListener.calls.length`);
          done();
        },
        0,
      );
    });
github aurelia / aurelia / packages / __tests__ / runtime-html / select-value-observer.spec.ts View on Github external
it('uses private method handleNodeChange as callback', async function () {
        for (const isMultiple of [true, false]) {
          const { ctx, el, sut } = createFixture([], [], isMultiple);

          const callbackSpy = createSpy(sut, 'handleNodeChange', true);

          sut.bind(LF.none);

          el.appendChild(ctx.createElement('option'));

          await Promise.resolve();

          assert.strictEqual(callbackSpy.calls.length, 1, 'callbackSpy.calls.length');

          sut.unbind(LF.none);
        }
      });
    }
github aurelia / aurelia / packages / __tests__ / kernel / di.integration.spec.ts View on Github external
beforeEach(function () {
    container = DI.createContainer();
    ITransient = DI.createInterface('ITransient').withDefault(x => x.transient(Transient));
    ISingleton = DI.createInterface('ISingleton').withDefault(x => x.singleton(Singleton));
    instance = new Instance();
    IInstance = DI.createInterface('IInstance').withDefault(x => x.instance(instance));
    callback = createSpy(() => new Callback());
    ICallback = DI.createInterface('ICallback').withDefault(x => x.callback(callback));
    get = createSpy(container, 'get', true);
  });
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / checked-observer.spec.ts View on Github external
function createFixture(hasSubscriber: boolean, value: any, prop: string) {
      const ctx = TestContext.createHTMLTestContext();
      const { container, lifecycle, observerLocator, scheduler } = ctx;

      const el = ctx.createElementFromMarkup(`<input type="checkbox">`) as ObservedInputElement;
      el[prop] = value;
      ctx.doc.body.appendChild(el);

      const sut = observerLocator.getObserver(LF.none, el, 'checked') as CheckedObserver;
      observerLocator.getObserver(LF.none, el, prop);

      const subscriber = { handleChange: createSpy() };
      if (hasSubscriber) {
        sut.subscribe(subscriber);
      }

      return { ctx, value, container, lifecycle, observerLocator, scheduler, el, sut, subscriber };
    }
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / value-attribute-observer.spec.ts View on Github external
function createFixture(hasSubscriber: boolean) {
        const ctx = TestContext.createHTMLTestContext();
        const { container, lifecycle, observerLocator, scheduler } = ctx;

        const el = ctx.createElementFromMarkup(`<input type="${inputType}">`) as HTMLInputElement;
        ctx.doc.body.appendChild(el);

        const sut = observerLocator.getObserver(LF.none, el, 'value') as ValueAttributeObserver;

        const subscriber = { handleChange: createSpy() };
        if (hasSubscriber) {
          sut.subscribe(subscriber);
        }

        return { ctx, container, lifecycle, observerLocator, el, sut, subscriber, scheduler };
      }
github aurelia / aurelia / packages / __tests__ / 1-kernel / di.spec.ts View on Github external
function setup() {
    const sut = DI.createContainer();
    const register = createSpy();

    return { sut, register };
  }