react-dom/test-utils#Simulate TypeScript Examples

The following examples show how to use react-dom/test-utils#Simulate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewCommentModal.spec.tsx    From apps with GNU Affero General Public License v3.0 6 votes vote down vote up
it('should recommend users previously mentioned', async () => {
  let queryPreviouslyMentioned = false;
  renderComponent({}, [
    {
      request: {
        query: RECOMMEND_MENTIONS_QUERY,
        variables: { postId: 'p1', query: '' },
      },
      result: () => {
        queryPreviouslyMentioned = true;
        return {
          data: {
            recommendedMentions: [
              { name: 'Lee', username: 'sshanzel', image: 'sample.image.com' },
            ],
          },
        };
      },
    },
  ]);
  const input = await screen.findByRole('textbox');
  input.innerText = '@';
  Simulate.keyDown(input, { key: '@' });
  await waitForNock();
  expect(queryPreviouslyMentioned).toBeTruthy();
});
Example #2
Source File: NewCommentModal.spec.tsx    From apps with GNU Affero General Public License v3.0 5 votes vote down vote up
it('should recommend users based on query', async () => {
  let queryMatchingNameOrUsername = false;
  renderComponent({}, [
    {
      request: {
        query: RECOMMEND_MENTIONS_QUERY,
        variables: { postId: 'p1', query: '' },
      },
      result: () => {
        return {
          data: {
            recommendedMentions: [
              { name: 'Ido', username: 'idoshamun', image: 'sample.image.com' },
            ],
          },
        };
      },
    },
    {
      request: {
        query: RECOMMEND_MENTIONS_QUERY,
        variables: { postId: 'p1', query: 'l' },
      },
      result: () => {
        queryMatchingNameOrUsername = true;
        return {
          data: {
            recommendedMentions: [
              { name: 'Lee', username: 'sshanzel', image: 'sample.image.com' },
            ],
          },
        };
      },
    },
  ]);
  const input = await screen.findByRole('textbox');
  input.innerText = '@';
  Simulate.keyDown(input, { key: '@' });
  await new Promise((resolve) => setTimeout(resolve, 500));
  input.innerText = '@l';
  Simulate.keyDown(input, { key: 'l' });
  await waitForNock();
  expect(queryMatchingNameOrUsername).toBeTruthy();
});