Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
target

GitHub Action

Assert Actual Is Expected

v1

Assert Actual Is Expected

target

Assert Actual Is Expected

Write tests in GitHub Workflows for integration tests and build pipelines

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Assert Actual Is Expected

uses: prompt/actions-assert@v1

Learn more about this action in prompt/actions-assert

Choose a version

Assert

A GitHub Action for asserting actual is expected in GitHub Workflows. Designed for GitHub Action integration tests and build pipelines.

  • Cast action input values from strings to type for type safety
  • Add custom Javascript assertions to your project to meet unique testing requirements
  • Run tests against multiple values using each
jobs:
  test-actor:
    runs-on: ubuntu-latest
    steps:
      - name: Test actor is @shrink
        uses: pr-mpt/actions-assert@v1
        with:
          assertion: npm://@assertions/is-equal
          actual: ${{ github.actor }}
          expected: shrink

Jump to examples ↓

Inputs

Name Description Default Examples
assertion Reference to a supported assertion npm://@assertions/is-equal
actual Dynamic value to perform test on ${{steps.m.outputs.greeting}}
expected Value that actual should match Hello, World!
type A supported data type that actual and expected will be cast to before performing assertion string string json number
each Parse multi-line actual into many values and test each false true false

Assertions

An assertion is a Javascript function that accepts expected and actual parameters then returns a Result. A Result has a boolean pass parameter and a message string.

module.exports = function (expected, actual) {
  return {
    pass: (actual === expected),
    message: `compared ${actual} to ${expected}`
  }
}

Assertions are resolved using type and name accepted in type://name format.

Type Resolved To Example
workflows A Javascript file in .github/workflows/assertions that exports an assertion as default workflows://is-equal
npm An npm package with an assertion as the main exported module npm://@assertions/is-equal

npm

A collection of assertions is available via npm within the @assertions organisation on npm.

Package Test
@assertions/is-equal actual is equal in value to expected
@assertions/is-strictly-equal actual is equal in value and type to expected
@assertions/starts-with actual starts with expected

Data Types

Name Description
string A Javascript String
number A Javascript Number
json JavaScript value or object from JSON.parse()

Outputs

Name Description Example
message Human readable result of the assertion Value is Hello, World!
pass Boolean describing whether the assertion passed true

Examples

SemVer Aliases Are Prefixed

pr-mpt/actions-semver-aliases generates aliases for a Semantic Version with an optional prefix, here we test that this prefix is applied to each alias.

jobs:
  test-aliases-are-prefixed:
    runs-on: ubuntu-latest
    steps:
      - name: Generate SemVer aliases with prefix
        id: prefixed
        uses: pr-mpt/actions-semver-aliases@v1
        with:
          version: "3.14.1"
          prefix: "v"
          major: true
          minor: false
      - name: Assert alias is prefixed
        uses: pr-mpt/actions-assert@v1
        with:
          assertion: npm://@assertions/starts-with
          each: true
          actual: "${{ steps.prefixed.outputs.list }}"
          expected: "v"