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 createScopeForTest(bindingContext = {}, parentBindingContext) {
if (parentBindingContext) {
return Scope.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, parentBindingContext, null)));
}
return Scope.create(0 /* none */, bindingContext, OverrideContext.create(0 /* none */, bindingContext, null));
}
// export type CustomAttribute = Writable & IComponentLifecycleMock;
assert.strictEqual(host.textContent, '', 'host.textContent #6');
runUnbindLifecycle(lifecycle, sut, baseFlags | unbindFlags1);
if (unbindTwice) {
runUnbindLifecycle(lifecycle, sut, baseFlags | unbindFlags1);
}
// -- Round 2 --
sut.items = items;
const expectedText3 = sut.items ? sut.items.join('') : '';
runBindLifecycle(lifecycle, sut, baseFlags | bindFlags2, scope);
if (bindTwice) {
if (newScopeForDuplicateBind) {
scope = Scope.create(baseFlags, scope.bindingContext);
}
runBindLifecycle(lifecycle, sut, baseFlags | bindFlags2, scope);
}
runAttachLifecycle(lifecycle, sut, baseFlags | attachFlags2);
assert.strictEqual(host.textContent, expectedText3, 'host.textContent #7');
if (attachTwice) {
runAttachLifecycle(lifecycle, sut, baseFlags | attachFlags2);
assert.strictEqual(host.textContent, expectedText3, 'host.textContent #8');
}
applyMutations(sut, mutations);
const expectedText4 = sut.items ? sut.items.join('') : '';
it('evaluates undefined bindingContext', function () {
const scope = Scope.create(LF.none, undefined, null);
expect(foo.evaluate(LF.none, scope, null)).to.equal(undefined);
expect(hello.evaluate(LF.none, scope, null)).to.equal(undefined);
});
it('connects undefined bindingContext', function () {
const scope = Scope.create(LF.none, undefined, null);
(binding.observeProperty as any).resetHistory();
foo.connect(LF.none, scope, binding as any);
expect(binding.observeProperty.callCount).to.equal(0);
hello.connect(LF.none, scope, binding as any);
expect(binding.observeProperty).to.have.been.calledWith(LF.none, scope.overrideContext, 'arg');
});
it('{}, null', function () {
const bindingContext = {} as any;
const actual = Scope.create(LF.none, bindingContext, null);
assert.strictEqual(actual.bindingContext, bindingContext, `actual.bindingContext`);
assert.instanceOf(actual.overrideContext, Object, `actual.overrideContext`);
assert.strictEqual(actual.overrideContext.bindingContext, bindingContext, `actual.overrideContext.bindingContext`);
assert.strictEqual(actual.overrideContext.parentOverrideContext, null, `actual.overrideContext.parentOverrideContext`);
});
it('null, null', function () {
const actual = Scope.create(LF.none, null, null);
assert.strictEqual(actual.bindingContext, null, `actual.bindingContext`);
assert.instanceOf(actual.overrideContext, Object, `actual.overrideContext`);
assert.strictEqual(actual.overrideContext.bindingContext, null, `actual.overrideContext.bindingContext`);
assert.strictEqual(actual.overrideContext.parentOverrideContext, null, `actual.overrideContext.parentOverrideContext`);
});
it('{}, {}', function () {
const bindingContext = {} as any;
const overrideContext = {} as any;
const actual = Scope.create(LF.none, bindingContext, overrideContext);
assert.strictEqual(actual.bindingContext, bindingContext, `actual.bindingContext`);
assert.strictEqual(actual.overrideContext, overrideContext, `actual.overrideContext`);
assert.strictEqual(actual.overrideContext.bindingContext, undefined, `actual.overrideContext.bindingContext`);
assert.strictEqual(actual.overrideContext.parentOverrideContext, undefined, `actual.overrideContext.parentOverrideContext`);
});
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));
}
const ctx = {};
const args = Array(count);
for (let i = 0; i < count; ++i) {
const prop = args[i] = `$${i}`;
ctx[prop] = 1;
if (expr === undefined) {
expr = new AccessScopeExpression(prop, 0);
} else {
expr = new BinaryExpression('+', expr, new AccessScopeExpression(prop, 0));
}
}
const container = RuntimeConfiguration.createContainer();
const observerLocator = createObserverLocator(container);
const target = {val: 0};
const sut = new PropertyBinding(expr as any, target, 'val', BindingMode.toView, observerLocator, container);
const scope = Scope.create(LF.none, ctx, null);
sut.$bind(LF.fromBind, scope);
assert.strictEqual(target.val, count, `target.val`);
for (let i = 0; i < count; ++i) {
ctx[args[i]] = 2;
}
assert.strictEqual(target.val, count * 2, `target.val`);
const ctx2 = {};
for (let i = 0; i < count; ++i) {
ctx2[args[i]] = 3;
}
const scope2 = Scope.create(LF.none, ctx2, null);
getScope(sut: CustomAttribute) { return Scope.create(LF.none, sut, null); }
},