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 BeforeNavigation hook 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.BeforeNavigation });
const hooked = await sut.invokeBeforeNavigation(
[router.createViewportInstruction('testing')], navigationInstruction) as ViewportInstruction[];
assert.strictEqual(hooked[0].componentName, 'hooked-testing', `hooked`);
await tearDown();
});
it('works with no hooks', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
const hooked = await sut.invokeTransformFromUrl('testing', navigationInstruction);
assert.strictEqual(hooked, 'testing', `hooked`);
await tearDown();
});
it('uses a TransformFromUrl hook returning viewport instructions', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
sut.addHook(
(url: string, navigationInstruction: INavigatorInstruction) =>
Promise.resolve([router.createViewportInstruction(`hooked-${url}`)]),
{ type: HookTypes.TransformFromUrl });
const hooked = await sut.invokeTransformFromUrl('testing', navigationInstruction) as ViewportInstruction[];
assert.strictEqual(hooked[0].componentName, 'hooked-testing', `hooked[0].componentName`);
await tearDown();
});
it('uses a TransformToUrl hook getting viewport instructions returning string', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
sut.addHook(
(viewportInstructions: ViewportInstruction[], navigationInstruction: INavigatorInstruction) =>
Promise.resolve(`hooked-${viewportInstructions[0].componentName}`),
{ type: HookTypes.TransformToUrl });
const hooked = await sut.invokeTransformToUrl(
[router.createViewportInstruction('testing')], navigationInstruction) as string;
assert.strictEqual(hooked, 'hooked-testing', `hooked`);
await tearDown();
});
it('uses a TransformToUrl hook getting string returning string', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
sut.addHook((url: string, navigationInstruction: INavigatorInstruction) => Promise.resolve(`hooked-${url}`),
{ type: HookTypes.TransformToUrl });
const hooked = await sut.invokeTransformToUrl('testing', navigationInstruction) as string;
assert.strictEqual(hooked, 'hooked-testing', `hooked`);
await tearDown();
});
it('can be created', function () {
const sut = new HookManager();
});
it('uses a TransformToUrl hook with alternating types', async function () {
const { router, tearDown, navigationInstruction } = await createFixture();
const sut = new HookManager();
const hook = (input: string | ViewportInstruction[], navigationInstruction: INavigatorInstruction): Promise =>
Promise.resolve(typeof input === 'string' ? [router.createViewportInstruction(`hooked-${input}`)] : `hooked-${input[0].componentName}`);
const str = 'testing';
sut.addHook(hook, { type: HookTypes.TransformToUrl });
let hooked: string | ViewportInstruction[] = await sut.invokeTransformToUrl(str, navigationInstruction) as ViewportInstruction[];
assert.strictEqual(hooked[0].componentName, `hooked-${str}`, `hooked`);
sut.addHook(hook, { type: HookTypes.TransformToUrl });
hooked = await sut.invokeTransformToUrl(str, navigationInstruction) as string;
assert.strictEqual(hooked, `hooked-hooked-${str}`, `hooked-hooked`);
sut.addHook(hook, { type: HookTypes.TransformToUrl });