Skip to content

Latest commit

 

History

History
371 lines (269 loc) · 9.08 KB

queries.md

File metadata and controls

371 lines (269 loc) · 9.08 KB

查询相关 API

类型说明

TWaitforParams:

参数 类型 必须 默认值 说明
container HTMLElement window.document
timeout number 1000 失效时间
interval number 50 查询间隔
mutationObserverOptions MutationObserverInit {subtree: true, childList: true, attributes: true, characterData: true } 监听器参数

按照选择器查询

querySelector

function querySelector(selectors: string): HTMLElement;

参数:

参数 类型 必须 说明
selectors string 选择器,同 docuemt.querySelector 一致

用法:

const btns = testUtils.querySelectorAll(".btns");

querySelectorAll

function querySelectorAll(selectors: string): HTMLElement[];

参数:

参数 类型 必须 说明
selectors string 选择器,同 docuemt.querySelectorAll 一致

用法:

const btns = testUtils.querySelectorAll(".btns");

waitForQuerySelector

async function waitForQuerySelector(
  selectors: string,
  params?: TParams
): Promise<HTMLElement>;

参数:

参数 类型 必须 说明
selectors string 选择器,同 docuemt.querySelector 一致
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

const btn = await testUtils.waitForQuerySelector(".async-btn");

waitForQuerySelectorAll

async function waitForQuerySelectorAll(
  selectors: string,
  params?: TParams
): Promise<HTMLElement[]>;

参数:

参数 类型 必须 说明
selectors string 选择器,同 docuemt.querySelectorAll 一致
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

const btns = await testUtils.waitForQuerySelectorAll(".async-btns");

按照文本查询

queryByText

function queryByText(text: string, selector?: string): HTMLElement;

参数:

参数 类型 必须 说明
text string 文本内容,部分匹配即可
selector string 选择器,同 docuemt.querySelector 一致

用法:

// <Text>Hello World!!!</Text>
const textView = testUtils.queryByText("Hello World");

queryByTextAll

function queryAllByText(text: string, selector?: string): HTMLElement[];

参数:

参数 类型 必须 说明
text string 文本内容,部分匹配即可
selector string 选择器,同 docuemt.querySelector 一致

用法:

// <Text>Hello World!!</Text>
// <View>Hello World!!!</View>
const textViews = testUtils.queryAllByText("Hello World");

waitForQueryByText

async function waitForQueryByText(
  text: string,
  selector?: string,
  params?: TWaitforParams
): HTMLElement;

参数:

参数 类型 必须 说明
text string 文本内容,部分匹配即可
selector string 选择器,同 docuemt.querySelector 一致
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <Text>Hello World!!!</Text>
const textView = async testUtils.waitForQueryByText("Hello World");

waitForQueryAllByText

async function waitForQueryAllByText(
  text: string,
  selector?: string,
  params?: TWaitforParams
): HTMLElement[];

参数:

参数 类型 必须 说明
text string 文本内容,部分匹配即可
selector string 选择器,同 docuemt.querySelector 一致
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <Text>Hello World!!</Text>
// <View>Hello World!!!</View>
const textViews = async testUtils.waitForQueryAllByText("Hello World");

按照 Placeholder 查询

queryByPlaceholder

function queryByPlaceholder(text: string): HTMLElement;

参数:

参数 类型 必须 说明
text string placeholder 内容

用法:

// <input placeholder="hello" />
const input = testUtils.queryByPlaceholder("hello");

queryAllByPlaceholder

function queryAllByPlaceholder(text: string): HTMLElement[];

参数:

参数 类型 必须 说明
text string placeholder 内容

用法:

// <input placeholder="hello" />
// <input placeholder="hello" />
const inputs = testUtils.queryAllByPlaceholder("hello");

waitForQueryByPlaceholder

async function waitForQueryByPlaceholder(
  text: string,
  params?: TParams
): Promise<HTMLElement>;

参数:

参数 类型 必须 说明
text string placeholder 内容
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <input placeholder="async-placeholde" />
const input = await testUtils.waitForQueryByPlaceholder("async-placeholder");

waitForQueryAllByPlaceholder

async function waitForQueryAllByPlaceholder(
  text: string,
  params?: TParams
): Promise<HTMLElement[]>;

参数:

参数 类型 必须 说明
text string placeholder 内容
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <input placeholder="async-placeholde" />
// <input placeholder="async-placeholde" />
const inputs = await testUtils.waitForQueryAllByPlaceholder(
  "async-placeholder"
);

按照属性查询

queryByAttribute

function queryByAttribute(attr: string, value: any): HTMLElement;

参数:

参数 类型 必须 说明
attr string 属性 key
value any 属性 value

用法:

// <div key="value" />
const view = testUtils.queryByAttribute("key", "value");

queryAllByAttribute

function queryAllByAttribute(attr: string, value: any): HTMLElement[];

参数:

参数 类型 必须 说明
attr string 属性 key
value any 属性 value

用法:

// <div key="value" />
// <div key="value" />
const view = testUtils.queryAllByAttribute("key", "value");

waitForQueryByAttribute

async function waitForQueryByAttribute(
  attr: string,
  value: string,
  params?: TParams
): Promise<HTMLElement>;

参数:

参数 类型 必须 说明
attr string 属性 key
value any 属性 value
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <div key="value" />
const view = await testUtils.waitForQueryByAttribute("key", "value");

waitForQueryAllByAttribute

async function waitForQueryAllByAttribute(
  attr: string,
  value: string,
  params?: TParams
): Promise<HTMLElement[]>;

参数:

参数 类型 必须 说明
attr string 属性 key
value any 属性 value
params TWaitforParams 参数:见 TWaitforParams 说明

用法:

// <div key="value" />
// <div key="value" />
const inputs = await testUtils.waitForQueryAllByAttribute("key", "value");