How to use the @aurelia/testing.TestContext.createHTMLTestContext 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__ / router / browser-navigator.spec.ts View on Github external
function createFixture() {
    const ctx = TestContext.createHTMLTestContext();
    const { lifecycle, scheduler, dom } = ctx;
    // const originalWnd = ctx.wnd;

    // const mockWnd = new MockWindow(originalWnd, originalWnd.history, originalWnd.location);
    // const addEventListener = createSpy(mockWnd, 'addEventListener');
    // const removeEventListener = createSpy(mockWnd, 'removeEventListener');

    // (DOM as Writable).window = mockWnd;

    const sut = new BrowserNavigator(scheduler, dom);
    const mockBrowserHistoryLocation = new MockBrowserHistoryLocation();
    mockBrowserHistoryLocation.changeCallback = sut.handlePopstate;
    sut.history = mockBrowserHistoryLocation as any;
    sut.location = mockBrowserHistoryLocation as any;

    function tearDown() {
github aurelia / aurelia / packages / __tests__ / 5-jit-html / template-compiler.ce_and_surrogate.spec.ts View on Github external
it(title, async function () {
      let host: HTMLElement;
      try {
        const ctx = TestContext.createHTMLTestContext();
        const aurelia = new Aurelia(ctx.container);
        host = ctx.createElement('div');

        ctx.container.register(...resources);

        const Root = CustomElement.define(
          { name: 'app', template },
          root === undefined ? class App {} : root
        );

        aurelia.app({ host: host, component: Root });

        aurelia.start();

        await assertFn(ctx, host, aurelia.container.get(Root));
github aurelia / aurelia / packages / __tests__ / 5-jit-html / computed-observer.spec.ts View on Github external
async function createFixture(template: string | Node, $class: Constructable | null, ...registrations: any[]) {
    const ctx = TestContext.createHTMLTestContext();
    const { container, lifecycle, observerLocator } = ctx;
    registrations = Array.from(new Set([...registrations]));
    container.register(...registrations);
    const testHost = ctx.doc.body.appendChild(ctx.createElement('div'));
    const appHost = testHost.appendChild(ctx.createElement('app'));
    const au = new Aurelia(container);
    const App = CustomElement.define({ name: 'app', template, strategy: BindingStrategy.proxies }, $class);
    const component = new App();

    au.app({ host: appHost, component });
    await au.start().wait();

    return {
      ctx: ctx,
      au,
      container,
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / target-observers.spec.ts View on Github external
it(title, function () {
      const ctx = TestContext.createHTMLTestContext();
      const el = ctx.createElementFromMarkup(`<div style="${staticStyle}"></div>`);
      const sut = new StyleAttributeAccessor(ctx.scheduler, LifecycleFlags.none, el);
      sut.setValue(input, LifecycleFlags.fromBind);

      const actual = sut.getValue();
      assert.strictEqual(actual, expected);
    });
  }
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__ / jit-html / if-else.spec.ts View on Github external
beforeEach(function () {
    ctx = TestContext.createHTMLTestContext();
  });
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / value-attribute-observer.spec.ts View on Github external
function createFixture() {
        const ctx = TestContext.createHTMLTestContext();
        const { container, observerLocator } = 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() };
        sut.subscribe(subscriber);

        return { ctx, container, observerLocator, el, sut, subscriber };
      }
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__ / jit-html / kitchen-sink.spec.ts View on Github external
it.skip('render hook', async function () {

    const ctx = TestContext.createHTMLTestContext();
    const App = CustomElement.define({
      name: 'app',
      template: `<template></template>`
    },                                       class {
      public $nodes: INodeSequence;
      public render() {
        this.$nodes = new NodeSequenceFactory(ctx.dom, 'foo').createNodeSequence();
      }
    });

    const au = new Aurelia(ctx.container);

    const host = ctx.createElement('div');
    const component = new App();

    au.app({ host, component });
github aurelia / aurelia / packages / __tests__ / 2-runtime / controller.spec.ts View on Github external
function setup() {
    resetId('au$component');

    const ctx = TestContext.createHTMLTestContext();
    const { container, lifecycle, dom, scheduler } = ctx;
    const templateFactory = container.get(ITemplateFactory);
    const renderContext = new RenderContext(dom, container, null);
    const $loc = h('div');
    const host = h('div', null, $loc);
    const loc = dom.convertToRenderLocation($loc);
    const calls = container.get(CallCollection);

    recordCalls(Controller, calls);
    recordCalls(If, calls);

    return {
      ctx,
      calls,
      container,
      scheduler,