Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
afterEach(() => {
cleanup();
// lots of tests can leave a post-drop click blocker
// this cleans it up before every test
fireEvent.click(window);
if (window.getComputedStyle.mockRestore) {
window.getComputedStyle.mockRestore();
}
if (Element.prototype.getBoundingClientRect.mockRestore) {
Element.prototype.getBoundingClientRect.mockRestore();
}
});
}
// description
expect(queryAllByText(extensionDescription)).toHaveLength(1);
// name
expect(queryAllByText(extensionName)).toHaveLength(1);
// update button
expect(queryAllByText(updateText)).toHaveLength(1);
// delete button
const deleteButton = getByText(deleteText);
expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled
// click the delete button so that the delete confirmation dialog opens
fireEvent.click(deleteButton);
// click the confirmation dialog delete button and make sure callback is called
const dialog = getAllByRole('dialog')[0];
fireEvent.click(getDialogButton(dialog, deleteText));
expect(mockOnDelete).toHaveBeenCalledTimes(1);
});
const { queryAllByTestId, queryByText, queryAllByText } = render(
)
expect(queryAllByTestId('input').length).toBe(2)
let removes
await sleep(33)
removes = queryAllByText('Remove Field')
fireEvent.click(removes[removes.length - 1])
await sleep(33)
removes = queryAllByText('Remove Field')
fireEvent.click(removes[removes.length - 1])
await sleep(33)
expect(queryAllByTestId('input').length).toBe(0)
await sleep(33)
fireEvent.click(queryByText('Add Field'))
await sleep(33)
fireEvent.click(queryByText('Add Field'))
await sleep(33)
expect(queryAllByTestId('input').length).toBe(2)
expect(queryAllByTestId('input')[0].value).toBe('123')
expect(queryAllByTestId('input')[1].value).toBe('123')
})
export function clickConfirmButton(button) {
jest.useFakeTimers()
fireEvent.click(button)
jest.runAllTimers()
jest.useRealTimers()
}
it('closes modal onClick', () => {
const { getByTestId } = render();
fireEvent.click(getByTestId('close'));
expect(onCloseSpy).toHaveBeenCalled();
});
});
test("allows toggling interception of requests", async () => {
const promiseFn = () => Promise.resolve("done")
const { getByText, getByLabelText, queryByText, rerender } = render()
fireEvent.click(getByLabelText("Pause new requests"))
rerender(
<>
)
await waitForElement(() => getByText("Pending"))
expect(queryByText("Fulfilled")).not.toBeInTheDocument()
fireEvent.click(getByText("run"))
await waitForElement(() => getByText("Fulfilled"))
})
test('clicking a tab does not change the active tab', () => {
const tab = getByText('Name A');
fireEvent.click(tab);
const secondContent = getByText('Second Content');
expect(secondContent).toBeInTheDocument();
});
throw new Error('Could not find uncontrolled container component');
}
const radioLabel = uncontrolledContainer.firstChild;
if (!typeIs.element(radioLabel)) {
throw new Error('Could not find the label element');
}
const radio = radioLabel.firstChild;
if (!typeIs.input(radio)) {
throw new Error('Could not find the radio input element');
}
fireEvent.click(radioLabel);
test('onChange fires once when the label is clicked', () => {
expect(uncontrolledOnChange.mock.calls.length).toBe(1);
});
test('radio button becomes checked when clicked', () => {
expect(radio.checked).toBe(true);
});
describe('and the default prop is set', () => {
const uncontrolledContainer = render(
Radio Button 1
Radio Button 1
{ id: 2, name: 'Mastercard' },
];
const { getByLabelText } = render(
<form> (
)}
/>
);
const input = getByLabelText('Mastercard') as HTMLInputElement;
expect(input.checked).toBe(false);
fireEvent.click(input);
expect(input.checked).toBe(true);
});
</form>
await act(async () => {
fireEvent.click(getByLabelText('Allow video download'));
return deferred.resolve({ ...video, show_download: true });
});