Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('uses a TransformToUrl hook getting viewport instructions returning viewport instructions', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
sut.addHook(
(viewportInstructions: ViewportInstruction[], navigationInstruction: INavigatorInstruction) =>
Promise.resolve([router.createViewportInstruction(`hooked-${viewportInstructions[0].componentName}`)]),
{ type: HookTypes.TransformToUrl });
const hooked = await sut.invokeTransformToUrl(
[router.createViewportInstruction('testing')], navigationInstruction) as ViewportInstruction[];
assert.strictEqual(hooked[0].componentName, 'hooked-testing', `hooked`);
await tearDown();
});
it('sets a TransformToUrl hook with alternating types through api', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const str = 'testing';
let hooked: string | ViewportInstruction[] = await router.hookManager.invokeTransformToUrl(str, navigationInstruction) as string;
assert.strictEqual(hooked, `${str}`, `not hooked`);
const hookFunction = (input: string | ViewportInstruction[], navigationInstruction: INavigatorInstruction): Promise =>
Promise.resolve(input.length > 0
? typeof input === 'string' ? [router.createViewportInstruction(`hooked-${input}`)] : `hooked-${input[0].componentName}`
: input);
router.addHook(hookFunction, { type: HookTypes.TransformToUrl });
router.addHook(hookFunction, { type: HookTypes.TransformToUrl });
router.addHook(hookFunction, { type: HookTypes.TransformToUrl });
hooked = await router.hookManager.invokeTransformToUrl(str, navigationInstruction) as ViewportInstruction[];
assert.strictEqual(hooked[0].componentName, `hooked-hooked-hooked-${str}`, `hooked-hooked-hooked`);
await tearDown();
});