Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createFixture(template, $class, registrations = [], autoStart = true, ctx = TestContext.createHTMLTestContext()) {
const { container, lifecycle, scheduler, observerLocator } = ctx;
container.register(...registrations);
const root = ctx.doc.body.appendChild(ctx.doc.createElement('div'));
const host = root.appendChild(ctx.createElement('app'));
const au = new Aurelia(container);
const App = CustomElement.define({ name: 'app', template }, $class || class {
});
const component = new App();
let startPromise = Promise.resolve();
if (autoStart) {
au.app({ host: host, component });
startPromise = au.start().wait();
}
return {
startPromise,
ctx,
host: ctx.doc.firstElementChild,
container,
lifecycle,
scheduler,
testHost: root,
},
class App {
public items: any[];
public display: boolean;
public count: number;
public afterCompileChildren() {
this.items = initialItems;
this.display = false;
this.count = count;
}
}
);
const host = ctx.createElement('div');
const au = new Aurelia(container);
const task = au.register(TestConfiguration)
.app({ host, component: Component, strategy })
.start();
const component = au.root.controller.bindingContext;
await task.wait();
assert.strictEqual(trimFull(host.textContent), elseText.repeat(count), `trimFull(host.textContent) === elseText.repeat(count)`);
execute(component as any, ctx.scheduler, host, count, ifText, elseText);
au.stop();
assert.strictEqual(trimFull(host.textContent), '', `trimFull(host.textContent) === ''`);
});
});
it(`\n----\n${testTitle}`, async function() {
const Foo = CustomElement.define(
{ name: 'foo', template: <template>{fooContentTemplate}</template> },
class Foo { items = fooItems }
);
const App = CustomElement.define(
{ name: 'app', template: <template>{appContentTemplate}</template> },
class App { message = 'Aurelia' }
);
const ctx = TestContext.createHTMLTestContext();
ctx.container.register(Foo);
const au = new Aurelia(ctx.container);
const host = ctx.createElement('div');
const component = new App();
au.app({ host, component });
await au.start().wait();
assert.strictEqual(host.textContent, expectedTextContent, `host.textContent`);
if (customAssertion) {
await customAssertion(ctx, host, component, component.$controller.controllers[0] as any as IFoo);
}
await tearDown(au);
});
}
export function setup(ctx: HTMLTestContext, template: string | Node, $class: Constructable | null, ...registrations: any[]) {
const { container, lifecycle, observerLocator } = ctx;
container.register(...registrations);
const host = ctx.createElement('app');
const au = new Aurelia(container);
const App = CustomElementResource.define({ name: 'app', template }, $class);
const component = new App() as any;
return { container, lifecycle, host, au, component, observerLocator };
}
const { container } = ctx;
const HostElement = defineAndRegisterElementWithChildren(container, childrenOptions);
const ChildOne = defineAndRegisterElement('child-one', container);
const ChildTwo = defineAndRegisterElement('child-two', container);
const component = defineAndRegisterHost(
`
`,
container
);
const au = new Aurelia(container);
const host = ctx.createElement(CustomElement.getDefinition(component).name);
au.app({ host, component });
au.start();
const hostViewModel = (host as any).$controller.viewModel;
const viewModel = (host.children[0] as any).$controller.viewModel;
return {
au,
hostViewModel,
viewModel,
ChildOne,
ChildTwo
};
}
import { DebugConfiguration } from '@aurelia/debug';
import { BasicConfiguration } from '@aurelia/jit-html-browser';
import { Aurelia } from '@aurelia/runtime';
import { App } from './app';
window['au'] = new Aurelia()
.register(BasicConfiguration, DebugConfiguration)
.app({ host: document.querySelector('app'), component: new App() })
.start();
setup() {
const container = exports.AuDOMConfiguration.createContainer();
const au = new runtime_1.Aurelia(container);
const lifecycle = container.get(runtime_1.ILifecycle);
const host = AuNode.createHost();
return { au, container, lifecycle, host };
},
createTextDefinition(expression, name = `${expression}-text`) {
function setup(): SpecContext {
const ctx = TestContext.createHTMLTestContext();
const { container, dom, lifecycle, observerLocator, renderingEngine: re } = ctx;
const au = new Aurelia(container);
const host = dom.createElement('div');
return { container, dom, au, host, lifecycle, re, observerLocator };
}
import { BasicConfiguration } from '@aurelia/jit';
import { Aurelia } from '@aurelia/runtime';
import { App } from './app';
import { IContainer } from '@aurelia/kernel';
import { register } from '@aurelia/plugin-svg';
import { State } from './state';
import { Pythagoras } from './pythagoras';
window['App'] = App;
window['Pythagoras'] = Pythagoras;
let state: State;
const au = window['au'] = new Aurelia()
.register(
{
register(container: IContainer) {
state = container.get(State);
register(container);
}
},
BasicConfiguration,
Pythagoras as any
)
.app({ host: document.querySelector('app'), component: new App(state) });
au
.start();