playwright-fluent
Version:
Fluent API around playwright
57 lines (56 loc) • 2.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const playwright_1 = require("playwright");
const SUT = tslib_1.__importStar(require("."));
describe('doesNotExist', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return an error when page has not been initalized', async () => {
// Given
const page = undefined;
// When
// Then
const expectedError = new Error("Cannot check that 'foobar' does not exist because no browser has been launched");
await SUT.doesNotExist('foobar', page).catch((error) => expect(error).toMatchObject(expectedError));
});
test('should return false when selector exists on the page - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
// When
const result = await SUT.doesNotExist('body', page);
// Then
expect(result).toBe(false);
});
test('should return true when selector does not exist on the page - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
// When
const result = await SUT.doesNotExist('foobar', page);
// Then
expect(result).toBe(true);
});
test('should return true when playright API throws an internal error', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
page.$ = () => {
throw new Error('internal error!');
};
// When
const result = await SUT.doesNotExist('body', page);
// Then
expect(result).toBe(true);
});
});
;