Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
xit('should unbind if it is bound', function () {
const { sut } = createFixture();
const scope: any = {};
sut['$scope'] = scope;
sut.$state = State.isBound;
sut['targetObserver'] = {} as any;
const unobserveSpy = createSpy(sut, 'unobserve');
const unbindSpy = dummySourceExpression.unbind = createSpy();
(dummySourceExpression as any).$kind |= ExpressionKind.HasUnbind;
sut.$unbind(LF.fromUnbind);
assert.strictEqual(sut['$scope'], undefined, `sut['$scope']`);
assert.strictEqual(sut['$state'] & State.isBound, 0, `sut['$state'] & State.isBound`);
// expect(unobserveSpy, `unobserveSpy`).to.have.been.calledWith(true);
// expect(unbindSpy, `unbindSpy`).to.have.been.calledWith(LF.fromUnbind, scope, sut);
});
});
beforeEach(function () {
getDesignParamtypes = createSpy(DI, 'getDesignParamtypes', true);
});
// eslint-disable-next-line mocha/no-hooks
it('queues consecutive calls', async function () {
const { sut, tearDown, callback } = setup();
const callbackSpy = createSpy(sut, 'dequeue' as keyof typeof sut);
sut.activate(callback);
const length = sut.length;
sut.pushState({}, null, '#one');
sut.replaceState("test", null, '#two');
sut.back();
sut.forward();
assert.deepStrictEqual(
callbackSpy.calls,
[],
`callbackSpy.calls`,
);
assert.strictEqual(sut.length, length, `sut.length`);
assert.strictEqual(sut['queue'].length, 4, `sut.queue.length`);
it(_`getObserver() - throws if $observers is undefined`, function () {
const { sut } = setup();
const obj = {};
const writeSpy = createSpy(Reporter, 'write');
Reflect.defineProperty(obj, '$observers', { value: undefined });
sut.getObserver(LF.none, obj, 'foo');
writeSpy.restore();
assert.deepStrictEqual(
writeSpy.calls,
[
[0, {}],
],
`writeSpy.calls`,
);
});
it('should add the specified eventListener to the node if the node is specified', function (done) {
const node = ctx.dom.createElement('div');
const eventListener = createSpy();
ctx.dom.addEventListener('click', eventListener, node);
node.dispatchEvent(new ctx.CustomEvent('click', { bubbles: true }));
setTimeout(
() => {
assert.strictEqual(eventListener.calls.length, 1, `eventListener.calls.length`);
done();
},
0,
);
});
it('uses private method handleNodeChange as callback', async function () {
for (const isMultiple of [true, false]) {
const { ctx, el, sut } = createFixture([], [], isMultiple);
const callbackSpy = createSpy(sut, 'handleNodeChange', true);
sut.bind(LF.none);
el.appendChild(ctx.createElement('option'));
await Promise.resolve();
assert.strictEqual(callbackSpy.calls.length, 1, 'callbackSpy.calls.length');
sut.unbind(LF.none);
}
});
}
beforeEach(function () {
container = DI.createContainer();
ITransient = DI.createInterface('ITransient').withDefault(x => x.transient(Transient));
ISingleton = DI.createInterface('ISingleton').withDefault(x => x.singleton(Singleton));
instance = new Instance();
IInstance = DI.createInterface('IInstance').withDefault(x => x.instance(instance));
callback = createSpy(() => new Callback());
ICallback = DI.createInterface('ICallback').withDefault(x => x.callback(callback));
get = createSpy(container, 'get', true);
});
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 };
}
function createFixture(hasSubscriber: boolean) {
const ctx = TestContext.createHTMLTestContext();
const { container, lifecycle, observerLocator, scheduler } = 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() };
if (hasSubscriber) {
sut.subscribe(subscriber);
}
return { ctx, container, lifecycle, observerLocator, el, sut, subscriber, scheduler };
}
function setup() {
const sut = DI.createContainer();
const register = createSpy();
return { sut, register };
}