| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * @vitest-environment node
- */
- import { describe, it, expect } from 'vitest';
- import { BaseOptions } from '../../src/types';
- import { E2ETestError } from '../../src/errors';
- import { DEFAULT_TIMEOUTS, SELECTOR_STRATEGIES } from '../../src/constants';
- describe('@d8d/e2e-test-utils 基础功能', () => {
- describe('类型定义', () => {
- it('应该正确导出 BaseOptions 类型', () => {
- const options: BaseOptions = { timeout: 1000 };
- expect(options.timeout).toBe(1000);
- });
- it('BaseOptions 应该支持可选属性', () => {
- const options: BaseOptions = {};
- expect(options.timeout).toBeUndefined();
- });
- });
- describe('错误类', () => {
- it('应该能够创建 E2ETestError 实例', () => {
- const error = new E2ETestError({
- operation: 'testOperation',
- target: 'testTarget',
- expected: 'expectedValue',
- actual: 'actualValue',
- });
- expect(error).toBeInstanceOf(Error);
- expect(error.name).toBe('E2ETestError');
- expect(error.context.operation).toBe('testOperation');
- expect(error.context.target).toBe('testTarget');
- });
- it('E2ETestError 应该包含格式化的错误消息', () => {
- const error = new E2ETestError({
- operation: 'selectOption',
- target: 'dropdown',
- expected: 'Option A',
- actual: 'Option B',
- });
- expect(error.message).toContain('selectOption failed');
- expect(error.message).toContain('dropdown');
- });
- });
- describe('常量定义', () => {
- it('DEFAULT_TIMEOUTS 应该包含所有必需的超时配置', () => {
- expect(DEFAULT_TIMEOUTS.static).toBeDefined();
- expect(DEFAULT_TIMEOUTS.async).toBeDefined();
- expect(DEFAULT_TIMEOUTS.networkIdle).toBeDefined();
- expect(DEFAULT_TIMEOUTS.static).toBe(2000);
- expect(DEFAULT_TIMEOUTS.async).toBe(5000);
- expect(DEFAULT_TIMEOUTS.networkIdle).toBe(10000);
- });
- it('SELECTOR_STRATEGIES 应该包含所有策略', () => {
- expect(SELECTOR_STRATEGIES).toContain('data-testid');
- expect(SELECTOR_STRATEGIES).toContain('aria-label + role');
- expect(SELECTOR_STRATEGIES).toContain('text content + role');
- expect(SELECTOR_STRATEGIES).toHaveLength(3);
- });
- });
- describe('Vitest 配置验证', () => {
- it('当前测试应该正常运行', () => {
- expect(true).toBe(true);
- });
- it('Vitest 应该支持 TypeScript', () => {
- const value: string = 'TypeScript support verified';
- expect(value).toBe('TypeScript support verified');
- });
- });
- });
|