Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`${psSpec.expectation} if ${psSpec.description} AND ${hooksSpec.expectation} if ${hooksSpec.description} AND ${flagsSpec.expectation} if ${flagsSpec.description}`, function () {
// Arrange
const { sut } = createCustomElement('foo');
psSpec.setProps(sut);
sut.$scope = Scope.create(LF.none, sut, null);
sut.$bindingHead = sut.$bindingTail = null;
sut.$componentHead = sut.$componentTail = null;
sut.$componentHead = sut.$componentTail = null;
sut.$hooks = hooksSpec.getHooks();
const expectedFlags = flagsSpec.getExpectedFlags();
const flags = flagsSpec.getFlags();
// Act
sut.$unbind(flags);
// Assert
if (psSpec.callsBehaviors) {
hooksSpec.verifyBehaviorInvocation(sut, expectedFlags);
} else {
sut.verifyNoFurtherCalls();
}
// ce #1 controller
.addCall(2, 'bound', LF.fromBind)
// ce #1
.addCall(1, 'bound', LF.fromBind),
'2',
);
sut.attach(flags);
assert.deepStrictEqual(
calls,
expectedCalls
// ce #1 controller
.addCall(2, 'attach', LF.none)
.addCall(2, 'attachCustomElement', LF.fromAttach)
// ce #1
.addCall(1, 'attaching', LF.fromAttach)
// ce #1 controller
.addCall(2, 'attachControllers', LF.fromAttach)
// if #1 controller
.addCall(4, 'attach', LF.fromAttach)
.addCall(4, 'attachCustomAttribute', LF.fromAttach)
// if #1
.addCall(3, 'attaching', LF.fromAttach)
.addCall(3, 'attachView', LF.fromAttach)
}
const overrideContext = {
...OverrideContext.create(LF.none, object, null),
$displayName: displayName,
$propertyName: propertyName,
$value: value,
$object: object,
$config: rule.config,
// returns the name of a given property, given just the property name (irrespective of the property's displayName)
// split on capital letters, first letter ensured to be capitalized
$getDisplayName: this.getDisplayName
};
return expression.evaluate(
LF.none,
// TODO: fix these types in the runtime so this silly cast is not needed
Scope.create(LF.none, object, overrideContext as unknown as IOverrideContext),
this.locator
) as string;
}
it('01.', function () {
const { au, lifecycle, host, component } = setupAndStart(ctx, `<template><div>bar</div></template>`, null);
component.foo = true;
lifecycle.processFlushQueue(LifecycleFlags.none);
expect(host.textContent).to.equal('bar');
component.foo = false;
lifecycle.processFlushQueue(LifecycleFlags.none);
expect(host.textContent).to.equal('');
tearDown(au, lifecycle, host);
});
it(_`getObserver() - Map.foo - returns MapObserver`, function () {
const { sut } = setup();
const obj = new Map();
const actual = sut.getObserver(LF.none, obj, 'foo');
assert.strictEqual(actual.constructor.name, DirtyCheckProperty.name, `actual.constructor.name`);
assert.instanceOf(actual, DirtyCheckProperty, `actual`);
});
function createFixture(initialValue: Anything = '', options = [], multiple = false) {
const ctx = TestContext.createHTMLTestContext();
const { dom, lifecycle, observerLocator } = ctx;
const optionElements = options.map(o => `<option value="${o}">${o}</option>`).join('\n');
const markup = `<select>\n${optionElements}\n</select>`;
const el = ctx.createElementFromMarkup(markup) as HTMLSelectElement;
const sut = observerLocator.getObserver(LF.none, el, 'value') as SelectValueObserver;
sut.setValue(initialValue, LF.fromBind);
return { ctx, lifecycle, el, sut, dom };
}
);
class App {
public items = ['1', '2', '3'];
}
CustomElementResource.define(definition, App);
const component = new App();
au.app({ host, component });
au.start();
expect(host.textContent).to.equal('123');
component.items.splice(1, 1, '5', '6', '7');
lifecycle.processFlushQueue(LifecycleFlags.none);
expect(host.textContent).to.equal('15673');
component.items.pop();
lifecycle.processFlushQueue(LifecycleFlags.none);
expect(host.textContent).to.equal('1567');
});
});
export function createScopeForTest(bindingContext: any = {}, parentBindingContext?: any): IScope {
if (parentBindingContext) {
return Scope.create(LF.none, bindingContext, OverrideContext.create(LF.none, bindingContext, OverrideContext.create(LF.none, parentBindingContext, null)));
}
return Scope.create(LF.none, bindingContext, OverrideContext.create(LF.none, bindingContext, null));
}
function runAttachLifecycle(ctx: HTMLTestContext, item: IComponent) {
ctx.lifecycle.beginAttach();
item.$attach(LifecycleFlags.none);
ctx.lifecycle.endAttach(LifecycleFlags.none);
}
function createFixture() {
const ctx = TestContext.createHTMLTestContext();
const { container, lifecycle, observerLocator, scheduler } = ctx;
const el = ctx.createElementFromMarkup(`<input>`) as IInputElement;
ctx.doc.body.appendChild(el);
const sut = ctx.observerLocator.getObserver(LifecycleFlags.none, el, 'value') as ValueAttributeObserver;
ctx.observerLocator.getObserver(LifecycleFlags.none, el, 'value');
return { ctx, container, lifecycle, observerLocator, el, sut, scheduler };
}
});