Pankod

Pankod

  • Docs
  • Github

›Features

Introduction

  • Getting Started
  • What's included?
  • Setup
  • Structure

Features

  • Styling
  • Unit Testing
  • Enviroment Variables

Project CLI

  • Overview
  • Usage

Unit Testing

This boilerplate uses Jest and Svelte Testing Library for unit testing.

Example testing functions from svelte-boilerplate.

Testing Components

import HelloWorld from './index.svelte';
import { render } from '@testing-library/svelte'

describe('Hello World', () => {
    it('renders Hello World! text', () => {
        const { container, getAllByText } = render(HelloWorld)

        expect(getAllByText('Hello').length).toBe(1)
        expect(getAllByText('World').length).toBe(2)

        expect(container.getElementsByClassName('title').length).toBe(1)
        expect(container.getElementsByClassName('title__top').length).toBe(1)
        expect(container.getElementsByClassName('title__front').length).toBe(1)
        expect(container.getElementsByClassName('title__back').length).toBe(1)

        expect(container).toMatchSnapshot()
    });
});

Testing Services


describe('Http request tests', () => {
    test('200 test', async () => {
        const result = await Http.Request('GET', '/200');
        expect(result.success).toEqual(true);
    });

    test('404 test', async () => {
        try {
            await Http.Request('GET', '/404');
        } catch (error) {
            expect(error.status).toEqual(404);
        }
    });

    test('Catch test', async () => {
        try {
            await Http.Request('GET', '');
        } catch (error) {
            expect(error.code).toBeUndefined();
        }
    });
});

← StylingEnviroment Variables →
  • Testing Components
  • Testing Services
Pankod
Docs
Getting StartedFeaturesSetup
Community
Twitter
More
GitHubStar
Pankod Open Source
Copyright © 2019 pankod