Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('SelfBindingBehavior', function () {
const container: IContainer = DI.createContainer();
let sut: SelfBindingBehavior;
let binding: PropertyBinding;
let originalCallSource: () => void;
// eslint-disable-next-line mocha/no-hooks
beforeEach(function () {
sut = new SelfBindingBehavior();
binding = new PropertyBinding(undefined, undefined, undefined, undefined, undefined, container as any);
originalCallSource = binding['callSource'] = function () { return; };
binding['targetEvent'] = 'foo';
sut.bind(undefined, undefined, binding as any);
});
// TODO: test properly (different binding types)
it('bind() should apply the correct behavior', function () {
assert.strictEqual(binding['selfEventCallSource'] === originalCallSource, true, `binding['selfEventCallSource'] === originalCallSource`);
it(`enables the handler class to provide registrations for data`, () => {
const container = DI.createContainer();
const data = {};
container.register(
Registration.singleton('.css', FakeCSSHandler)
);
container.register(
Registration.defer('.css', data)
);
const service = container.get(FakeCSSService);
assert.strictEqual(service.data, data);
});
it('components do not inherit parent component styles', function () {
const rootContainer = DI.createContainer();
const parentContainer = rootContainer.createChild();
const registry = new CSSModulesProcessorRegistry();
registry.register(parentContainer, {});
const childContainer = parentContainer.createChild();
const parentResources = new RuntimeCompilationResources(parentContainer);
const childResources = new RuntimeCompilationResources(childContainer);
const fromParent = parentResources.find(CustomAttribute, 'class');
const fromChild = childResources.find(CustomAttribute, 'class');
assert.equal(fromParent.name, 'class');
assert.equal(fromChild, null);
});
it(`inherits non-resource obj keyed factories from root`, function () {
const type = class {};
const key = {} as any;
const parent = DI.createContainer();
parent.register(Registration.singleton(key, type));
const factoryFromParent = parent.getFactory(key);
const child = parent.createChild();
const factoryFromChild = child.getFactory(key);
assert.strictEqual(factoryFromParent, factoryFromChild);
});
it(`parse [${defs.map(d => d.pattern)}] -> interpret [${value}] -> match=[${match}]`, function () {
let receivedRawName: string;
let receivedRawValue: string;
let receivedParts: string[];
@attributePattern(...defs)
class ThePattern {}
for (const { pattern } of defs) {
ThePattern.prototype[pattern] = (rawName, rawValue, parts) => {
receivedRawName = rawName;
receivedRawValue = rawValue;
receivedParts = parts;
};
}
const container = DI.createContainer();
container.register(ThePattern as any);
const interpreter = container.get(ISyntaxInterpreter);
const attrPattern = container.get(IAttributePattern);
interpreter.add(attrPattern.$patternDefs);
const result = interpreter.interpret(value);
if (match != null) {
assert.strictEqual(
attrPattern.$patternDefs.map(d => d.pattern).includes(result.pattern),
true,
`attrPattern.$patternDefs.map(d => d.pattern).indexOf(result.pattern) >= 0`
);
attrPattern[result.pattern](value, 'foo', result.parts);
assert.strictEqual(receivedRawName, value, `receivedRawName`);
assert.strictEqual(receivedRawValue, 'foo', `receivedRawValue`);
assert.deepStrictEqual(receivedParts, result.parts, `receivedParts`);
export function createObserverLocator(containerOrLifecycle?: IContainer | ILifecycle): IObserverLocator {
let container: IContainer;
if (containerOrLifecycle === undefined || !('get' in containerOrLifecycle)) {
container = DI.createContainer();
container.register(ILifecycleRegistration);
} else {
container = containerOrLifecycle as IContainer;
}
const lifecycle = container.get(ILifecycle);
const dummyLocator: any = {
handles(): boolean {
return false;
}
};
Registration.instance(IDirtyChecker, null).register(container);
Registration.instance(ITargetObserverLocator, dummyLocator).register(container);
Registration.instance(ITargetAccessorLocator, dummyLocator).register(container);
container.register(IObserverLocatorRegistration);
return container.get(IObserverLocator);
}
beforeEach(function () {
container = DI.createContainer();
});
export function createObserverLocator(containerOrLifecycle) {
let container;
if (containerOrLifecycle === undefined || !('get' in containerOrLifecycle)) {
container = DI.createContainer();
container.register(ILifecycleRegistration);
}
else {
container = containerOrLifecycle;
}
const dummyLocator = {
handles() {
return false;
}
};
Registration.instance(IDirtyChecker, null).register(container);
Registration.instance(ITargetObserverLocator, dummyLocator).register(container);
Registration.instance(ITargetAccessorLocator, dummyLocator).register(container);
container.register(IObserverLocatorRegistration);
return container.get(IObserverLocator);
}
createContainer() {
return this.register(DI.createContainer());
}
};
constructor(container: IContainer = DI.createContainer()) {
this.container = container;
this.task = LifecycleTask.done;
this._isRunning = false;
this._isStarting = false;
this._isStopping = false;
this._root = void 0;
this.next = (void 0)!;
Registration.instance(Aurelia, this).register(container);
}