playwright-fluent
Version:
Fluent API around playwright
75 lines (74 loc) • 3.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const playwright_1 = require("playwright");
const SUT = tslib_1.__importStar(require("../index"));
describe('get today date of page', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return today - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
// When
const result = await SUT.getToday(page);
// Then
expect(result).toBeDefined();
});
test('should return today as yyy-mm-dd - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
// When
const result = await SUT.getToday(page, 'yyyy-mm-dd');
// Then
expect(result).toBeDefined();
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/i);
});
test('should return today in short format - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
// When
const result = await SUT.getToday(page, {
locale: 'en',
intlOptions: { year: 'numeric', month: 'short', day: '2-digit' },
});
const result2 = await SUT.getToday(page, 'Jun 01, 2021');
// Then
expect(result).toBe(result2);
});
test('should return today as "Apr 15, 2021" - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
// When
const result = await SUT.getToday(page, 'Jun 01, 2021');
// Then
expect(result).toBeDefined();
expect(result).toMatch(/^[A-Z][a-z]{2}\s\d{2},\s\d{4}$/i);
});
test('should return an error when option is wrong', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
const badIntlOptions = {
day: 'foobar',
};
// When
const result = await SUT.getToday(page, { locale: 'en', intlOptions: badIntlOptions });
// Then
expect(result).toBe('RangeError: Value foobar out of range for Intl.DateTimeFormat options property day');
});
});
;