How to use the @aurelia/testing.assert.equal 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__ / integration / integration.spec.ts View on Github external
$it(`uses a tri-state-boolean`, function ({ host, ctx }) {
    const app = getViewModel(host);
    const tsb = host.querySelector(`tri-state-boolean`);
    const labels = toArray(tsb.querySelectorAll('label'));

    // assert radio buttons and selection
    assert.html.textContent(labels[0], app.noDisplayValue, `incorrect label for noValue`);
    assert.html.textContent(labels[1], app.trueValue, `incorrect label for true`);
    assert.html.textContent(labels[2], app.falseValue, `incorrect label for false`);
    assert.equal(labels[0].querySelector('input').checked, false, `should not have been checked for noValue`);
    assert.equal(labels[1].querySelector('input').checked, false, `should not have been checked for true`);
    assert.equal(labels[2].querySelector('input').checked, false, `should not have been checked for false`);

    // assert if the choice is changed in VM, it is propagated to view
    app.likesCake = true;
    ctx.scheduler.getRenderTaskQueue().flush();
    assert.equal(labels[1].querySelector('input').checked, true, `should have been checked for true`);

    // assert that when choice is changed from view, it is propagaetd to VM
    labels[2].click();
    ctx.scheduler.getRenderTaskQueue().flush();
    assert.equal(labels[2].querySelector('input').checked, true, `should have been checked for false`);
    assert.equal(app.likesCake, false, 'expected change to porapagate to vm');
  });
github aurelia / aurelia / packages / __tests__ / 5-jit-html / blur.integration.spec.ts View on Github external
dispatchEventWith(ctx, button, EVENTS.MouseDown);
            await ctx.scheduler.yieldRenderTask();

            assert.equal(component.hasFocus, false, '+ button@mousedown');

            // this is quite convoluted
            // and failing unexpectedly, commented out for good
            component.hasFocus = true;
            input.focus();
            dispatchEventWith(ctx, input, EVENTS.Focus, false);
            await ctx.scheduler.yieldRenderTask();
            // assert.equal(input, ctx.doc.activeElement, 'child > input === doc.activeElement (2)');
            // child input got focus
            // 1. blur got triggered -> hasFocus to false
            // 2. focus got triggered -> hasFocus to true
            assert.equal(component.hasFocus, true, 'child > input@focus');
          }
        },
github aurelia / aurelia / packages / __tests__ / integration / integration.spec.ts View on Github external
const app = getViewModel(host);
    const tsb = host.querySelector(`tri-state-boolean`);
    const labels = toArray(tsb.querySelectorAll('label'));

    // assert radio buttons and selection
    assert.html.textContent(labels[0], app.noDisplayValue, `incorrect label for noValue`);
    assert.html.textContent(labels[1], app.trueValue, `incorrect label for true`);
    assert.html.textContent(labels[2], app.falseValue, `incorrect label for false`);
    assert.equal(labels[0].querySelector('input').checked, false, `should not have been checked for noValue`);
    assert.equal(labels[1].querySelector('input').checked, false, `should not have been checked for true`);
    assert.equal(labels[2].querySelector('input').checked, false, `should not have been checked for false`);

    // assert if the choice is changed in VM, it is propagated to view
    app.likesCake = true;
    ctx.scheduler.getRenderTaskQueue().flush();
    assert.equal(labels[1].querySelector('input').checked, true, `should have been checked for true`);

    // assert that when choice is changed from view, it is propagaetd to VM
    labels[2].click();
    ctx.scheduler.getRenderTaskQueue().flush();
    assert.equal(labels[2].querySelector('input').checked, true, `should have been checked for false`);
    assert.equal(app.likesCake, false, 'expected change to porapagate to vm');
  });
github aurelia / aurelia / packages / __tests__ / 5-jit-html / blur.integration.spec.ts View on Github external
assert.equal(component.hasFocus, false, 'window@mousedown');
            await ctx.scheduler.yieldRenderTask();

            component.hasFocus = true;
            dispatchEventWith(ctx, ctx.doc.body, EVENTS.MouseDown);
            await ctx.scheduler.yieldRenderTask();

            assert.equal(component.hasFocus, false, 'document.body@mousedown');

            const button = testHost.querySelector('button');
            component.hasFocus = true;
            dispatchEventWith(ctx, button, EVENTS.MouseDown);
            await ctx.scheduler.yieldRenderTask();

            assert.equal(component.hasFocus, false, '+ button@mousedown');

            // this is quite convoluted
            // and failing unexpectedly, commented out for good
            component.hasFocus = true;
            input.focus();
            dispatchEventWith(ctx, input, EVENTS.Focus, false);
            await ctx.scheduler.yieldRenderTask();
            // assert.equal(input, ctx.doc.activeElement, 'child > input === doc.activeElement (2)');
            // child input got focus
            // 1. blur got triggered -> hasFocus to false
            // 2. focus got triggered -> hasFocus to true
            assert.equal(component.hasFocus, true, 'child > input@focus');
          }
        },
github aurelia / aurelia / packages / __tests__ / i18n / t / translation-render.spec.ts View on Github external
it('instantiated with instruction type', function () {
    const container = setup();
    const sut: IInstructionRenderer = new TranslationBindingRenderer(container.get(IExpressionParser), {} as unknown as IObserverLocator);
    assert.equal(sut.instructionType, TranslationInstructionType);
  });
github aurelia / aurelia / packages / __tests__ / i18n / t / translation-parameters-render.spec.ts View on Github external
it('creates attribute syntax without `to`', function () {
    const sut = setup();
    const pattern = 't-params.bind';
    const value = '{foo: "bar"}';

    const actual: AttrSyntax = sut[pattern](pattern, value, []);
    assert.equal(actual.command, pattern);
    assert.equal(actual.rawName, pattern);
    assert.equal(actual.rawValue, value);
    assert.equal(actual.target, '');
  });
});
github aurelia / aurelia / packages / __tests__ / i18n / t / translation-parameters-render.spec.ts View on Github external
it('creates attribute syntax without `to`', function () {
    const sut = setup();
    const pattern = 't-params.bind';
    const value = '{foo: "bar"}';

    const actual: AttrSyntax = sut[pattern](pattern, value, []);
    assert.equal(actual.command, pattern);
    assert.equal(actual.rawName, pattern);
    assert.equal(actual.rawValue, value);
    assert.equal(actual.target, '');
  });
});
github aurelia / aurelia / packages / __tests__ / validation / validate-binding-behavior.spec.ts View on Github external
const target: HTMLInputElement = (host as Element).querySelector("#target");
      assertControllerBinding(controller, 'person.name', target);

      controllerSpy.clearCallRecords();
      assert.equal(controller.errors.filter((e) => !e.valid && e.propertyName === 'name').length, 0, 'error1');
      await controller.validate();
      assert.equal(controller.errors.filter((e) => !e.valid && e.propertyName === 'name').length, 1, 'error2');

      await assertEventHandler(target, 'blur', 0, scheduler, controllerSpy);
      target.value = 'foo';
      await assertEventHandler(target, 'change', 0, scheduler, controllerSpy);

      controllerSpy.clearCallRecords();
      assert.equal(controller.errors.filter((e) => !e.valid && e.propertyName === 'name').length, 1, 'error3');
      await controller.validate();
      assert.equal(controller.errors.filter((e) => !e.valid && e.propertyName === 'name').length, 0, 'error4');
    },
    { template: `<input type="text">` }
github aurelia / aurelia / packages / __tests__ / 2-runtime / view-location.spec.ts View on Github external
};

      const locator = new ViewLocator();
      const model = new MyModel();

      const Component = locator.getViewComponentForObject(model);
      const instance: any = new Component();

      instance.$controller = {
        scope: {}
      };

      instance[lifecycleHook]();

      assert.isCustomElementType(Component);
      assert.equal(model.invoked, true);
    });
  });
github aurelia / aurelia / packages / __tests__ / 5-jit-html / template-compiler.harmony.spec.ts View on Github external
assert.equal(comp.hasFocus, true, 'comp.hasFocus === true (1)');
        assert.equal(comp.focus, 1);
        assert.equal(comp.blur, undefined);

        host.blur();
        assert.equal(comp.hasFocus, false, 'comp.hasFocus === false (1)');
        assert.equal(comp.focus, 1);
        assert.equal(comp.blur, 1);

        comp.hasFocus = true;
        await ctx.scheduler.yieldRenderTask();
        assert.strictEqual(ctx.doc.activeElement, host);
        assert.equal(comp.focus, 2);
        const div = host.querySelector('div');
        div.click();
        assert.equal(comp.focus, 2);
        assert.equal(comp.blur, 1);
      }
    },