Skip to content

Commit 03fd911

Browse files
committed
add test for next/amp
1 parent 2e409c8 commit 03fd911

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* When doing `next build` you would get the error below:
3+
* TypeScript error: Property 'amp-timeago' does not exist on type 'JSX.IntrinsicElements'.
4+
* https://stackoverflow.com/questions/50585952/property-amp-img-does-not-exist-on-type-jsx-intrinsicelements/50601125#50601125
5+
* The workaround in that SO post doesn't work in this (mono)repo so I ended up using @ts-expect-error and @ts-ignore
6+
*
7+
*/
8+
9+
export const config = { amp: true };
10+
11+
export async function getServerSideProps() {
12+
return {
13+
props: {
14+
time: new Date().toISOString(),
15+
},
16+
};
17+
}
18+
19+
function MyAmpPage({ time }: { time: string }) {
20+
const date = new Date(time);
21+
22+
return (
23+
<div>
24+
<p>Some time: {date.toJSON()}</p>
25+
{/* @ts-expect-error AMP Component not recognized by TypeScript */}
26+
<amp-timeago
27+
width="0"
28+
height="15"
29+
datetime={date.toJSON()}
30+
layout="responsive"
31+
data-testid="amp-timeago"
32+
>
33+
.{/* @ts-ignore */}
34+
</amp-timeago>
35+
</div>
36+
);
37+
}
38+
39+
export default MyAmpPage;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test.describe("next/amp", () => {
4+
test("should load and display the timeago component", async ({ page }) => {
5+
await page.goto("/amp");
6+
const timeago = await page.getByTestId("amp-timeago").textContent();
7+
expect(timeago).toBe("just now");
8+
});
9+
});

0 commit comments

Comments
 (0)