Check if any react elements are rendered
Get callback from parameters by the key
a key of the callbacks
parameter
callback by paramteres of the callbacks[callbackKey]
if callbacks
parameter is not setted
if the property value is not a function
const render = create(Component, defaultProps, {
queries: {
fooButton: {
component: 'button',
className: 'foo',
},
},
callbacks: {
onFooClick: ['fooButton', 'onClick'],
},
});
const engine = render({});
page.getCallback('onFooClick')({} as MouseEvent);
Get the arguments of the called hook function
a key of the hooks
parameter
the arguments with which the hook by key was called
if hooks
not setted
if hookOrder
not setted
if mockFunctionValue
not setted
if getMockArguments
not setted
import { vi } from "vitest";
function Component() {
const [counter, setCounter] = useState(0);
// ...
}
const render = create(Component, defaultProps, {
queries: {},
hooks: {
counter: useState,
},
hookOrder: [
"counter",
],
mockFunctionValue: (fn, value) => {
vi.mocked(fn).mockReturnValueOnce(value);
},
getMockArguments: (fn, callIndex) => {
return vi.mocked(fn).mock.calls[callIndex];
},
});
const engine = render({});
assert.strictEqual(
engine.getHookArguments("counter"),
0,
);
Get prop value from parameters by the key
a key of the properties
parameter
value by paramteres of the properties[propertyKey]
const render = create(Component, defaultProps, {
queries: {
content: {
component: 'div',
className: 'foo',
},
},
properties: {
contentChildren: ['content', 'children'],
},
});
const engine = render({});
const contentChildren = page.getProperty('contentChildren');
Root node of rendered react tree
Generated using TypeDoc
An object whose keys are keys of the
queries
parameter and whose values are accessors in the format ofreact-shallow-search