-
Notifications
You must be signed in to change notification settings - Fork 54
/
util.test.js
27 lines (22 loc) · 970 Bytes
/
util.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { expect, test } from '@playwright/test';
import { formatDate } from '../../public/scripts/util.js';
import '../coverage.js';
test('formatDate', () => {
expect(formatDate(new Date(0))).toEqual('January 1st 1970');
expect(formatDate(new Date('2023-05-13 12:00:00'))).toEqual('May 13th 2023');
});
test('toDataURL', async ({ page }) => {
// Needs to be tested in the browser because FileReader is not available in Node.js
// However, this approach does not support test coverage :'(
await page.goto('http://localhost:8080');
const dataURL = await page.evaluate(async () => {
const { toDataURL } = await import('./scripts/util.js');
const text = 'a Ā 𐀀 文 🦄';
const json = JSON.stringify({ text });
const dataURL = await toDataURL(json, 'application/json;charset=utf-8');
return dataURL;
});
expect(dataURL).toEqual(
'data:application/json;charset=utf-8;base64,eyJ0ZXh0IjoiYSDEgCDwkICAIOaWhyDwn6aEIn0=',
);
});