ts-utils
  • Getting Started
  • Contributing
  • Testing
  • Functions
    • Array Methods
      • isArr
      • isArrEmpty
      • pushUniqueValue
      • pushOrUpdate
    • Date Methods
      • toNow
      • formatDate
      • fromNow
    • Number Methods
      • toFixed
      • parseNumber
      • parseFormat
      • addUnit
      • addSeparators
      • formatNumber
      • ensureNumber
      • numberEmptyState
    • Object Methods
      • parseJSON
      • deepClone
      • parseNumValues
      • removeEmptyKeys
      • sanitizeQuery
      • removeKeys
      • renameKey
      • renameKeys
      • sortByKeyLength
      • querylize
      • parseNumericObj
      • reserveKeys
      • hasKeysAndValues
    • String Methods
      • randomStr
      • toUpperCase
      • toLowerCase
      • toFullUrl
      • initials
      • generateUuid
Powered by GitBook
On this page
  • Table of Content
  • Overview
  • Writing Tests
  • Running Tests
  • Continuous Integration

Was this helpful?

Testing

PreviousContributingNextFunctions

Last updated 11 months ago

Was this helpful?

Table of Content

Overview

The TS-Utils package uses , a popular testing framework for JavaScript and TypeScript, to ensure the reliability and correctness of its utility functions. Each utility category has its corresponding test file located in the , named after the category (e.g., string.test.ts, object.test.ts).

Writing Tests

To write tests for your contributions, create a new test file in the test folder, following the naming convention of <category>.test.ts. For example, if you're adding a new utility function to the array category, create/add to the file named array.test.ts Inside the test file, write your tests using Jest's testing syntax. Here's an example of how to structure a test for a chunk function in the array category:

typescript
import { chunk } from '../src/array';

describe('chunk', () => {
  it('should split an array into smaller chunks', () => {
    expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
  });
});

Running Tests

To run the tests for a specific utility category, use the following command:

bash
{{pnpm/npm/yarn}} test --array.test.ts

To run all the tests for the entire TS-Utils package, use the following command:

bash
{{pnpm/npm/yarn}} jest

This will execute all the tests defined in the test folder.

Continuous Integration

The TS-Utils package uses GitHub Actions for continuous integration (CI). When you submit a pull request, the CI workflow will automatically run the tests to ensure that your changes do not break existing functionality.

By following these guidelines and writing comprehensive tests for your contributions, you can help maintain the quality and reliability of the TS-Utils package.

Jest
test folder
Overview
Writing Tests
Running Tests
Continuous Integration