Skip to content

Polaris-Suite/polaris-suite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polaris Suite

Polaris suite is a easy to use, light and collaborative web tesiting package for javascript and typescript projects.

Visit polaris-suite docs for detailed information.

Table of Contents


Getting Started

Install Polaris-suite using npm:

npm install --save-dev polaris-suite

Let's create your first test. Start by creating a function in a file multiplication.js.

function multiply(a, b) {
    return a * b;
}
module.exports = multiply;

Or, for es6

export function multiply(a, b) {
    return a * b;
}

Then, create the actual test inside file multiplication.test.js ideally located inside test folder

import { test, expect } from "polaris-suite";
import { multiply } from "path-to-multiplication.js";

test('multiply 3 * 4 equals 12', () => {
    expect(multiply(3, 4)).equalsTo(12);
});

Note: As of now polaris-suite only supports commonJS module and not es6

Now, Add the script in package.json to run the test

{
    ... ,
    "scripts": {
        ... ,
        "test": "polaris test"
    },
    ...
}

Note: the path must be provided till the folder the test file is located and not the file name itself

Finally, run npm test in the terminal and the following message will be printed in the console:

PASS ✓ (multiply 3 * 4 equals 12)

Contragtulation, you just created your first test case in polaris-suite and executed it

For other functions and their property that you can use can be found in the Docs


Using Typescript

Polaris Suite will support typescript out of the box. There will be no need for any extra configuration to get started with typescript with polaris suite.

Note: It is not supported yet and will be added very soon


Documentation

For detailed documentation docs


Functions that can be used

function Parameters Description
expect() actual: any This is the most basic function that can be used in polaris-suite. It takes in a parameter that can be anything.
call() fn: function, params?: any[ ] This is another basic function that is used to test functions easily. It takes a function and optionally takes params array.
component() ele: HTML element This is another basic function that is used to test component easily. It takes a HTML element.
test() name: string, fn: function This is the function that will be treated as a test case in polaris-suite. It takes a name, and a function with no parameters and return value.
suite() name: string, fn: function This is the function that is used to group the test cases and create a test suite in polaris-suite. It takes a name, and a function with no parameters and return value.
result() This is the function that will soon be not needed to be explicity called but as of now has to be called in order to get summary of results when using suite

expect

The most basic function that can be used to test the equality or test the expectation of any kind of data (string, boolean, function, etc).

Parameters:

  • actual: any

Returns:

  • void

Properties

  • equalsTo() : takes a parameter expected of any type to check euqality with the actual value
  • toBeString() : check if actual is of string type
  • toBeNull() : check if actual is of null type
  • toBeBoolean() : check if actual is of boolean type
  • toBeObject() : check if actual is of object type
  • not : check the negation of equality
    • equalsTo()
    • toBeString()
    • toBeNull()
    • toBeBoolean()
    • toBeArray()
    • toBeObject()

call

Another basic function that can be used to test the return value or the expected return value of functions

Parameters:

  • fn: any
  • params?: any[ ]

Returns:

  • void

Properties

  • returns() : takes a parameter result of any type and an optional parameter of type WithDataOptions to check euqality with the return value of the function.
  • iterateWithData() : similar to returns expect it takes in a parameter of type DataTable and an optional parameter of type WithDataOptions and iterate over those value to check return value for multiple parameters.
  • not : check the negation of returns
    • returns()

component

Another basic function that can be used to test the html component

Parameters:

  • ele: HTML element

Returns:

  • void

Properties

  • haveStyle() : takes a parameter style of object type to check if the element has the provided style
  • contains() : takes a parameter child of type either string or HTML element and check if it is the child element of ele
  • not : check the negation
    • haveSytle()
    • contains()

test

This function is used to create a test case in polaris-suite. It is recommended to use it alongside suite() function but can be used alone too.

Parameters:

  • name: string
  • fn: function

Returns:

  • void

Properties: no properties, standalone function


suite

This function is used to group similar test cases together and run at once with detailed result of each test cases.

Parameters:

  • name: string
  • fn: function

Returns:

  • void

Properties: no properties, standalone function


result

has been called implicitly, no more need of calling explicitly

Helper function that will soon be no longer needed to be explicitly executed but for now needs to be called when using suite function to get result summary.

Parameters: no parameters

Returns:

  • void

Properties: no properties, standalone function


Types

It is a bare minimum guide to some custom types in polaris-suite to better understand its functions and functionality.

To dive deeper, head to docs - types

DataTable

type:

type DataTable = Array<{ arg: Array<any>, result: any, isNotEqual?: boolean }>

description:

used in parameter typing of call() function to take in the array of parameters to be passed in iterateWithData() function.


WithDataOptions

type:

type WithDataOptions = {
    async?: boolean;
}

description:

used in parameter typing of call() function as the optional parameters to specify the function has other properties like asynchronous, etc