Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert.strictEqual(totalPropObserver['collectionDeps']?.length, 1);
totalPropObserver['propertyDeps'].forEach((observerDep: SetterObserver, idx: number) => {
if (idx === 0) {
assert.instanceOf(observerDep, GetterObserver);
} else {
assert.instanceOf(observerDep, SetterObserver);
}
});
assert.strictEqual(host.textContent, '30' /* idx 0, 2, 4, 6, 8 only */);
component.items[0].isDone = false;
assert.strictEqual(component.activeItems.length, 6);
assert.strictEqual(host.textContent, '30');
ctx.container.get(IScheduler).getRenderTaskQueue().flush();
assert.strictEqual(host.textContent, '31');
}
},
it('adds handler with messageType and callback to the messageHandlers array', function () {
const ea = new EventAggregator() as EA;
const callback = function () { return; };
ea.subscribe(DinnerEvent, callback);
assert.strictEqual(ea.messageHandlers.length, 1, `ea.messageHandlers.length`);
assert.strictEqual(ea.messageHandlers[0].messageType, DinnerEvent, `ea.messageHandlers[0].messageType`);
assert.strictEqual(ea.messageHandlers[0].callback, callback, `ea.messageHandlers[0].callback`);
});
it('bind() should apply the correct behavior', function () {
assert.strictEqual(binding['debouncedMethod'] === originalFn, true, `binding['debouncedMethod'] === originalFn`);
assert.strictEqual(binding['debouncedMethod'].originalName, 'handleChange', `binding['debouncedMethod'].originalName`);
assert.strictEqual(binding.handleChange === originalFn, false, `binding.handleChange === originalFn`);
assert.strictEqual(typeof binding.handleChange, 'function', `typeof binding.handleChange`);
assert.notStrictEqual(binding['debounceState'], null, `binding['debounceState']`);
assert.strictEqual(typeof binding['debounceState'], 'object', `typeof binding['debounceState']`);
});
it('disconnect node observer', function () {
for (const isMultiple of [true, false]) {
const { sut } = createFixture([], [], isMultiple);
let count = 0;
const nodeObserver: any = { disconnect() {
count++;
} };
sut['nodeObserver'] = nodeObserver;
sut.unbind(LF.none);
assert.strictEqual(count, 1, `count`);
assert.strictEqual(sut['nodeObserver'], null, `sut['nodeObserver']`);
}
});
it('unsubscribes array observer', function () {
it(`translates raw object properties to attributes`, function () {
const ctx = TestContext.createHTMLTestContext();
const actual = sut(ctx.dom, tag, { title: 'asdf', foo: 'bar' });
const node = actual['node'] as Element;
assert.strictEqual(node.getAttribute('title'), 'asdf', `node.getAttribute('title')`);
assert.strictEqual(node.getAttribute('foo'), 'bar', `node.getAttribute('foo')`);
assert.strictEqual(actual['instructions'].length, 0, `actual['instructions'].length`);
assert.strictEqual(node.getAttribute('class'), null, `node.getAttribute('class')`);
});
this.timeout(5000);
const callback = async (qAnimal: QueueItem) => {
const animal = qAnimal as Animal;
await wait(100);
if (animal.name === 'dog') {
qAnimal.reject();
} else {
qAnimal.resolve();
}
};
const q = new Queue(callback as (item: QueueItem) => void);
q.enqueue(new Animal('dog', 'Pluto')).catch((error: Error) => { throw error; });
assert.strictEqual(q.pending.length, 0, `q.pending.length`);
q.enqueue(new Animal('cat', 'Figaro')).catch((error: Error) => { throw error; });
assert.strictEqual(q.pending.length, 1, `q.pending.length`);
assert.strictEqual(q.pending[0].cost, 1, `q.pending[0].cost`);
q.enqueue(new Animal('cat', 'Figaro II'), 2).catch((error: Error) => { throw error; });
assert.strictEqual(q.pending.length, 2, `q.pending.length`);
assert.strictEqual(q.pending[1].cost, 2, `q.pending[1].cost`);
q.enqueue([
new Animal('dog', 'Pluto III'),
new Animal('cat', 'Figaro III')], 3);
assert.strictEqual(q.pending.length, 4, `q.pending.length`);
assert.strictEqual(q.pending[2].cost, 3, `q.pending[2].cost`);
assert.strictEqual(q.pending[3].cost, 3, `q.pending[3].cost`);
q.enqueue([
new Animal('dog', 'Pluto IV'),
new Animal('cat', 'Figaro V')], [6, 7]);
assert.strictEqual(q.pending.length, 6, `q.pending.length`);
assert.strictEqual(q.pending[4].cost, 6, `q.pending[4].cost`);
assert.strictEqual(q.pending[5].cost, 7, `q.pending[5].cost`);
});
sut.yield(priority).then(() => {
if (priority !== TaskQueuePriority.microTask) {
assert.strictEqual(count, ++yieldCount, 'count === ++yieldCount');
if (yieldCount < iterations) {
yieldAndVerify();
} else {
task.cancel();
assert.isSchedulerEmpty();
done();
}
}
}).catch((error) => { throw error; });
}
[Foo5]
);
const fooEl = options.appHost.querySelector('div');
const rootVm = options.au.root.viewModel as any;
const foo5Vm = CustomAttribute.for(fooEl, 'foo5').viewModel as Foo5;
assert.strictEqual(foo5Vm.prop, NaN, '#1 <-> Foo1 initial');
assert.strictEqual(rootVm.prop, 'prop', '#1 <-> RootVm initial');
assert.strictEqual(options.appHost.textContent, 'prop');
rootVm.prop = 5;
assert.strictEqual(foo5Vm.prop, 5, '#2 <-> RootVm.prop << 5 -> foo5Vm');
assert.strictEqual((foo5Vm as any).$observers.prop.currentValue, 5, '#2 Foo5.$observer.prop.currentValue');
assert.strictEqual(rootVm.prop, 5, '#2 <-> RootVm.prop << 5 -> rootVm');
options.scheduler.getRenderTaskQueue().flush();
assert.strictEqual(options.appHost.textContent, '5');
const date = new Date();
foo5Vm.prop = date;
assert.strictEqual(foo5Vm.prop, date.getTime(), '#3 <-> foo1Vm.prop << Date');
assert.strictEqual(rootVm.prop, date.getTime(), '#3 <-> foo1Vm.prop << Date');
options.scheduler.getRenderTaskQueue().flush();
assert.strictEqual(options.appHost.textContent, date.getTime().toString());
rootVm.prop = NaN;
assert.strictEqual(Object.is(foo5Vm.prop, NaN), true, '#1 <-> Foo1 initial');
assert.strictEqual(Object.is(rootVm.prop, NaN), true, '#1 <-> RootVm initial');
options.scheduler.getRenderTaskQueue().flush();
assert.strictEqual(options.appHost.textContent, 'NaN');
await options.tearDown();
});
const subscription = ea.subscribe('dinner', callback);
const callback2 = function () { return; };
const subscription2 = ea.subscribe('dinner', callback2);
assert.strictEqual(ea.eventLookup.dinner.length, 2, `ea.eventLookup.dinner.length`);
assert.strictEqual(ea.eventLookup.dinner[0], callback, `ea.eventLookup.dinner[0]`);
assert.strictEqual(ea.eventLookup.dinner[1], callback2, `ea.eventLookup.dinner[1]`);
subscription.dispose();
assert.strictEqual(ea.eventLookup.dinner.length, 1, `ea.eventLookup.dinner.length`);
assert.strictEqual(ea.eventLookup.dinner[0], callback2, `ea.eventLookup.dinner[0]`);
subscription2.dispose();
assert.strictEqual(ea.eventLookup.dinner.length, 0, `ea.eventLookup.dinner.length`);
});
Object.keys(result[0].params).forEach((property) => {
if (params[property] === undefined) {
return;
}
assert.strictEqual(result[0].params[property].toUpperCase(), params[property].toUpperCase(), `result[0].params[property].toUpperCase()`);
});
});