How to use @testing-library/svelte - 10 common examples

To help you get started, we’ve selected a few @testing-library/svelte examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shipshapecode / shepherd / test / unit / components / shepherd-element.spec.js View on Github external
it('exitOnEsc: true - ESC cancels the tour', async() => {
      const tour = new Tour();
      const step = new Step(tour, {});
      const stepCancelSpy = spy(step, 'cancel');

      const { container } = render(ShepherdElement, {
        props: {
          step
        }
      });
      fireEvent.keyDown(container.querySelector('.shepherd-element'), { keyCode: 27 });
      expect(stepCancelSpy.called).toBe(true);
    });
github mdauner / sveltejs-forms / tests / utils.js View on Github external
async function renderAndWait(component, options) {
  const renderedComponent = render(component, options);
  await wait();
  return renderedComponent;
}
github shipshapecode / shepherd / test / unit / components / shepherd-button.spec.js View on Github external
it('is enabled when false', () => {
      const config = {
        disabled: false
      };

      const { container } = render(ShepherdButton, {
        props: {
          config
        }
      });

      const button = container.querySelector('.shepherd-button');
      expect(button.disabled).toBeFalsy();
    });
github YogliB / svelte-component-template / tests / MyAwesomeComponent.spec.js View on Github external
it('Should render greeting', () => {
		const { container } = render(MyAwesomeComponent, {
			props: { name: 'world' },
		});

		expect(container.querySelector('h1')).toHaveTextContent('Hello world!');
	});
});
github shipshapecode / shepherd / test / unit / components / shepherd-footer.spec.js View on Github external
it('renders buttons for each item passed to `options.buttons`', () => {
    const step = {
      options: {
        buttons: [
          defaultButtons.cancel,
          defaultButtons.next
        ]
      }
    };

    const { container } = render(ShepherdFooter, {
      props: {
        step
      }
    });

    const buttons = container.querySelectorAll('.shepherd-footer .shepherd-button');
    expect(buttons.length).toBe(2);

    const cancelButton = container.querySelector('footer .cancel-button');
    expect(cancelButton).toHaveAttribute('tabindex', '0');
    expect(cancelButton).toHaveClass('shepherd-button-secondary cancel-button shepherd-button');
    expect(cancelButton).toHaveTextContent('Exit');

    const nextButton = container.querySelector('footer .next-button');
    expect(nextButton).toHaveAttribute('tabindex', '0');
    expect(nextButton).toHaveClass('shepherd-button-primary next-button shepherd-button');
github mdauner / sveltejs-forms / tests / Form / Form.spec.js View on Github external
.string()
          .required()
          .email(),
      }),
    });
    const {
      container,
      component,
      getByPlaceholderText,
      getByText,
    } = await render(App, {
      props: { schema },
    });
    const emailInput = getByPlaceholderText('Email');

    await fireEvent.change(emailInput, {
      target: { value: 'invalid value' },
    });
    await fireEvent.blur(emailInput);
    await wait(() => {
      expect(getByText('user.email must be a valid email')).toBeInTheDocument();
    });
    expect(component.form.$$.ctx.$errors).toEqual({
      user: { email: 'user.email must be a valid email' },
    });

    expect(container.firstChild).toMatchSnapshot();
  });
github mdauner / sveltejs-forms / tests / Input / Input.spec.js View on Github external
it('does not validate on change if validateOnChange is false', async () => {
    const schema = yup.object().shape({
      email: yup.string().email(),
    });
    const { component, getByPlaceholderText } = await render(App, {
      props: { schema, validateOnChange: false },
    });

    const emailInput = getByPlaceholderText('Email');

    await fireEvent.change(emailInput, {
      target: { value: 'invalid value' },
    });
    await wait();

    expect(component.form.$$.ctx.$errors).toEqual({});
  });
github mdauner / sveltejs-forms / tests / Form / Form.spec.js View on Github external
it('click on submit button dispatches submit event and sets isSubmitting to true', async () => {
    const { component, getByText } = await render(App, {
      props: { onSubmit: jest.fn() },
    });
    const signInButton = getByText('Sign in');

    expect(component.form.$$.ctx.$isSubmitting).toBe(false);
    expect(signInButton).not.toHaveAttribute('disabled');

    await fireEvent.click(signInButton);
    await wait();
    expect(component.onSubmit).toHaveBeenCalledTimes(1);
    expect(signInButton).toHaveAttribute('disabled');
    expect(component.form.$$.ctx.$isSubmitting).toBe(true);
  });
github shipshapecode / shepherd / test / unit / components / shepherd-header.spec.js View on Github external
it('cancel icon cancels the tour', async() => {
    const tour = new Tour();
    const step = new Step(tour, {
      cancelIcon: {
        enabled: true
      }
    });
    const stepCancelSpy = spy(step, 'cancel');

    const { container } = render(ShepherdHeader, {
      props: {
        step
      }
    });

    fireEvent.click(container.querySelector('.shepherd-cancel-icon'));
    expect(stepCancelSpy.called).toBe(true);
  });
});
github mdauner / sveltejs-forms / tests / Input / Input.spec.js View on Github external
it('validates on blur if validateOnBlur is true', async () => {
    const schema = yup.object().shape({
      email: yup.string().email(),
    });
    const { component, getByPlaceholderText } = await render(App, {
      props: { schema, validateOnChange: false, validateOnBlur: true },
    });

    const emailInput = getByPlaceholderText('Email');

    await fireEvent.change(emailInput, {
      target: { value: 'invalid value' },
    });
    await fireEvent.blur(emailInput);
    await wait();

    expect(component.form.$$.ctx.$errors).toEqual({
      email: 'email must be a valid email',
    });
  });