/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { stripAnsi } from '../config/utils'; import { test, expect } from './pageTest'; test.describe('toBeChecked', () => { test('default', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked(); }); test('with checked:true', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked({ checked: true }); }); test('with checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeChecked({ checked: false }); }); test('with indeterminate:true', async ({ page }) => { await page.setContent(''); await page.locator('input').evaluate((e: HTMLInputElement) => e.indeterminate = true); const locator = page.locator('input'); await expect(locator).toBeChecked({ indeterminate: true }); }); test('with indeterminate:true and checked', async ({ page }) => { await page.setContent(''); await page.locator('input').evaluate((e: HTMLInputElement) => e.indeterminate = true); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ indeterminate: true, checked: false }).catch(e => e); expect(error.message).toContain(`Can\'t assert indeterminate and checked at the same time`); }); test('fail', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ timeout: 1000 }).catch(e => e); expect(stripAnsi(error.message)).toContain(`Timed out 1000ms waiting for expect(locator).toBeChecked()`); expect(stripAnsi(error.message)).toContain(`- Expect "toBeChecked" with timeout 1000ms`); }); test('with not', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeChecked(); }); test('with not and checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked({ checked: false }); }); test('fail with not', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).not.toBeChecked({ timeout: 1000 }).catch(e => e); expect(stripAnsi(error.message)).toContain(`Timed out 1000ms waiting for expect(locator).not.toBeChecked()`); expect(stripAnsi(error.message)).toContain(`- Expect "not toBeChecked" with timeout 1000ms`); expect(stripAnsi(error.message)).toContain(`locator resolved to `); }); test('fail with checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ checked: false, timeout: 1000 }).catch(e => e); expect(stripAnsi(error.message)).toContain(`Timed out 1000ms waiting for expect(locator).toBeChecked({ checked: false })`); expect(stripAnsi(error.message)).toContain(`- Expect "toBeChecked" with timeout 1000ms`); expect(stripAnsi(error.message)).toContain(`locator resolved to `); }); test('fail with indeterminate: true', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ indeterminate: true, timeout: 1000 }).catch(e => e); expect(stripAnsi(error.message)).toContain(`Timed out 1000ms waiting for expect(locator).toBeChecked({ indeterminate: true })`); expect(stripAnsi(error.message)).toContain(`- Expect "toBeChecked" with timeout 1000ms`); }); test('fail missing', async ({ page }) => { await page.setContent('