Skip to content

Commit

Permalink
test: fix typo in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Aug 9, 2021
1 parent d906c16 commit 4f0ed16
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 54 deletions.
3 changes: 2 additions & 1 deletion src/crawlAndSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const crawlAndSort = async (

if (
"singletons" in options &&
options.singletons?.includes(current.type) &&
Array.isArray(options.singletons) &&
options.singletons.includes(current.type) &&
!(current.type in collections)
) {
collections[current.type] = current;
Expand Down
File renamed without changes.
57 changes: 43 additions & 14 deletions test/pairedShortcodes-link.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
import test from "ava";
import * as sinon from "sinon";

import { injectPairedShortcodes } from "../src";
import { createDocument } from "./__testutils__/createDocument";

test.afterEach.always(() => {
sinon.restore();
});
import { linkResolver } from "./__testutils__/linkResolver";

import { link } from "../src";

test.serial("injects paired shorcodes", (t) => {
const injector = sinon.spy();
const args = ["testSlots", { url: "/bar" }] as const;

injectPairedShortcodes(injector);
test("returns link field resolved anchor tag", (t) => {
t.is(
`<a href="https://google.com">${args[0]}</a>`,
link()(...args, {
link_type: "Web",
url: "https://google.com",
}),
);
});

t.true(injector.called);
test("returns link field resolved blank anchor tag", (t) => {
t.is(
`<a href="https://google.com" target="_blank" rel="noopener noreferrer">${args[0]}</a>`,
link()(...args, {
link_type: "Web",
url: "https://google.com",
target: "_blank",
}),
);
});

test.serial("injects paired shorcodes with namespace", (t) => {
const namespace = "prismic";
test("returns document resolved anchor tag", (t) => {
t.is(
`<a href="/foo">${args[0]}</a>`,
link()(...args, createDocument({ url: "/foo" })),
);
});

const injector = sinon.spy();
test("returns document resolved anchor tag using link resolver", (t) => {
t.is(
`<a href="/foo">${args[0]}</a>`,
link(linkResolver)(...args, createDocument({ url: "/foo" })),
);
});

injectPairedShortcodes(injector, { shortcodesNamespace: namespace });
test("returns an empty anchor tag when link resolver is required but not provided", (t) => {
t.is(`<a>${args[0]}</a>`, link()(...args, createDocument()));
});

t.true(injector.args.every((args) => args[0].startsWith(namespace)));
test("returns document resolved anchor tag for current page", (t) => {
t.is(
`<a href="/bar" aria-current="page">${args[0]}</a>`,
link()(...args, createDocument({ url: "/bar" })),
);
});
53 changes: 14 additions & 39 deletions test/pairedShortcodes.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,26 @@
import test from "ava";
import * as sinon from "sinon";

import { createDocument } from "./__testutils__/createDocument";
import { injectPairedShortcodes } from "../src";

import { linkResolver } from "./__testutils__/linkResolver";
test.afterEach.always(() => {
sinon.restore();
});

import { link } from "../src";
test.serial("injects paired shorcodes", (t) => {
const injector = sinon.spy();

const args = ["testSlots", { url: "/bar" }] as const;
injectPairedShortcodes(injector);

test("returns link field resolved anchor tag", (t) => {
t.is(
`<a href="https://google.com">${args[0]}</a>`,
link()(...args, {
link_type: "Web",
url: "https://google.com",
}),
);
t.true(injector.called);
});

test("returns link field resolved blank anchor tag", (t) => {
t.is(
`<a href="https://google.com" target="_blank" rel="noopener noreferrer">${args[0]}</a>`,
link()(...args, {
link_type: "Web",
url: "https://google.com",
target: "_blank",
}),
);
});
test.serial("injects paired shorcodes with namespace", (t) => {
const namespace = "prismic";

test("returns document resolved anchor tag", (t) => {
t.is(
`<a href="/foo">${args[0]}</a>`,
link()(...args, createDocument({ url: "/foo" })),
);
});
const injector = sinon.spy();

test("returns document resolved anchor tag using link resolver", (t) => {
t.is(
`<a href="/foo">${args[0]}</a>`,
link(linkResolver)(...args, createDocument({ url: "/foo" })),
);
});
injectPairedShortcodes(injector, { shortcodesNamespace: namespace });

test("returns document resolved anchor tag for current page", (t) => {
t.is(
`<a href="/bar" aria-current="page">${args[0]}</a>`,
link()(...args, createDocument({ url: "/bar" })),
);
t.true(injector.args.every((args) => args[0].startsWith(namespace)));
});

0 comments on commit 4f0ed16

Please sign in to comment.