Dev Standards
  • Untitled
  • project-standards
    • project-success
      • index
      • production.s
    • taking-over-project
      • index
      • migrate-to-new-ios-certificates.mo
    • technical-agility
      • react-native-test.s
      • code-vocabulary-identical-business-vocabulary.s
      • under-15-minutes-project-installation.s
      • index
      • up-to-date-dependencies.s
  • react-native
    • react
      • get-element-size-or-position-with-onLayout.mo
      • binding-functions-in-react-component.s
      • enable-overflow-android.mo
    • setup
      • setup-code-push.mo
      • setup-facebook-login.mo
      • setup-and-deploy-new-project-to-staging.mo
      • add-cocoapods.mo
      • deploy-script.mo
      • setup-and-deploy-new-project-to-staging-with-hockeyapp.mo
      • add-native-module.mo
      • setup_firebase_multiple_envs.mo
      • remove-unnecessary-android-permissions.mo
      • deploy-to-production-android.mo
      • deploy-project-to-production
      • overriding-existing-app.s
      • patch-react-native-android.mo
      • setup-stripe-dev-standard.mo
    • features
      • icomoon.mo
      • lock-device-orientation.mo
      • clean-logout.s
      • deep-linking
      • offline-redux.mo
      • asyncstorage.mo
      • offline-mobx.mo
    • debugging
      • analyse-bug.mo
      • debug-network-calls.mo
      • debug-javascript-ios-device.mo
      • get-ios-logs.mo
      • debug-javascript.mo
      • handle-gradle-dependencies-clash.mo
      • debug-native-ios.mo
      • debug-two-ios-apps-simultaneously.mo
      • debug-native-android.mo
      • debug-webviews.mo
    • firebase
      • debug-events.mo
    • architecture
      • project-architecture.s
      • default-stack.s
      • file-naming.s
    • update
      • upgrade-react-native.mo
    • tests
      • setup-detox-jest.mo
    • use_http_links_in_react_native.mo
    • react-navigation
      • unmount-compoenent-on-page-change.mo
    • package-dependencies
      • handle-dependencies-with-yarn-override.mo
    • animations
      • react-native-animations.s
  • successful-sprint
    • coding
      • plan-your-ticket-to-improve-efficency.s
  • code-quality
    • components-state-testing.mo
    • mock-with-jest.mo
    • pull-request-template.s
    • pull_request_template
    • test-files-indentation.s
  • security
    • import_certificates_match.mo
    • 2FA.mo
  • contributing
    • contributing.mo
    • mo.s
    • standard.s
  • backend
    • graphql-js
      • getting-started-with-apollo-server-dataloader-knex.mo
    • node-js
      • handle-errors-and-exceptions-in-javascript.s
      • add-multiple-environments-configuration-on-loopback.s
    • django
      • deploy-to-aws.mo
      • create-user-model.mo
      • getting-started.mo
      • create-model-and-api.mo
  • performance
    • backend
      • cache-routes-using-varnish.mo
      • serve-images-as-static-files.mo
      • minimize-number-sql-queries.mo
      • python-investigation-tools.mo
      • how-to-investigate-performance.mo
      • output-sql-alchemy-orm-query.mo
    • front
      • how-to-investigate-performance.mo
      • table-and-chart-with-good-performance.mo
      • react-native-performance.s
      • simulate-network-iphone.mo
    • performance-decision-flow.s
  • git
    • merge-or-rebase-a-branch
  • editors
    • vscode
      • setup-vscode.mo
  • ops
    • docker
      • deploy-with-https.mo
  • templates
    • mo
  • react
    • redux
      • custom-redux-form-field.mo
      • pass-props-to-container.mo
    • component.s
    • lifecycle
      • trigger-action-on-props-update.mo
  • flowtype
    • flowtype.s
  • LICENCE
  • README
  • scrum
    • timebox.s
  • SUMMARY
Powered by GitBook
On this page
  • Owner: Pierre-Louis Le Portz
  • Why
  • Checks
  • Case 1: The tested file exports at least 1 named function
  • Case 2: The tested file exports only 1 function or element as default
  • Good examples
  • Case 1: Generic example
  • Case 1: A saga test with redux-saga-test-plan
  • Case 2: A react-native component
  • Bad examples // @TODO
  1. code-quality

test-files-indentation.s

Previouspull_request_templateNextsecurity

Last updated 7 years ago

Owner:

Why

Standardizing the indentation of a test file saves the developer 30 seconds per new function to test.

Checks

There are 2 cases:

Case 1: The tested file exports at least 1 named function

Use the following indentation even if only one function is tested:

  • 1 describe per file

    • 1 describe per function

    • 1 it for each case

Case 2: The tested file exports only 1 function or element as default

Use the following indentation:

  • 1 describe with the name of the file

    • 1 it for each functionality

Good examples

Case 1: Generic example

describe('Name of the tested file', () => {
  describe('function1', () => {
    it('does something', () => {
      //...
    });
    it('does some other thing', () => {
      //...
    });
  });

  describe('function2', () => {
    it('does something', () => {
      //...
    });
    it('does some other thing', () => {
      //...
    });
  });
});

Case 1: A saga test with redux-saga-test-plan

import { testSaga } from 'redux-saga-test-plan';
import { buyRoamingPackage, fetchRoamingBundlesSaga } from './sagas';
import { selectedRoamingPackageSelector } from '../../TopUps/Bundle/selectors';
import { setLoading } from '../../LoadingStatus/actions';

describe('sagas', () => {
  describe('buyRoamingPackage', () => {
    it('initializes the product and buy it', () => {
      const roamingPackage = { ouid: '4' };
      testSaga(buyRoamingPackage, { type: 'BUY_ROAMING_PACKAGE' })
        .next()
        .select(selectedRoamingPackageSelector)
        // ...
        .isDone();
    });
  });

  describe('fetchRoamingBundlesSaga', () => {
    it('fetches the roaming bundles and store them', () => {
      testSaga(fetchRoamingBundlesSaga, {
        type: 'FETCH_ROAMING_BUNDLES',
      })
        .next()
        .put(setLoading('roamingOffer', true))
        // ...
        .isDone();
    });
  });
});

Case 2: A react-native component

import React from 'react';
import IdentityRequirements from './IdentityRequirements';
import renderer from 'react-test-renderer';

describe('<IdentityRequirements />', () => {
  it('renders correctly', () => {
    const tree = renderer.create(<IdentityRequirements />);
    expect(tree.toJSON()).toMatchSnapshot();
  });
});

Bad examples // @TODO

Pierre-Louis Le Portz