Skip to content

Chunjee/expect.ahk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



A Test Anything Protocol (TAP) compliant unit testing package for AutoHotkey

Installation

In a terminal or command line navigated to your project folder:

npm install expect.ahk

In your code only the file export.ahk needs to be included:

#Include %A_ScriptDir%\node_modules
#Include expect.ahk\export.ahk
expect := new expect()

testVar := 2 + 2
expect.equal(testVar, 4)
expect.fullReport()

You may also review or copy the library from ./export.ahk on GitHub; #Include as you would normally when manually downloading.

Usage

Grants access to a class named expect with the following methods: .equal, .notEqual, .true, .false, .label, .group, .report, .fullReport, and .writeResultsToFile

expect := new expect()

; .equal checks and logs whether or not both arguments are the same
expect.label("string comparison")
expect.equal("StringExample", "StringExample")

expect.label("value testing")
expect.equal((1 > 0 ), true)

expect.label("true/false testing")
expect.true((1 == 1))
expect.false((1 != 1))
expect.notEqual(true,false)

expect.report()
expect.fullReport()
expect.writeResultsToFile()

Contributing

We kindly ask those interested to submit their contributions in the form of a pull request. Your efforts are sincerely appreciated. Thank you for your valuable contributions!

API

.equal

expect.equal([1, 2, 3], [1, 2, 3])

checks if param_actual and param_expected inputs are the same or equal. The comparison is always case-sensitive.

Aliases

.test

Arguments

Argument Type Description
param_actual number/string/object The actual value.
param_expected number/string/object The expected value.
param_note string (Optional) Additional notes for the test.

Returns

(boolean): Returns true if the values are equal, else false.

.notEqual

expect.notEqual({ "a":1 }, { "a":false })

checks if actual and expected inputs are NOT the same or equal. The comparison is always case-sensitive.

Arguments

Argument Type Description
param_actual number/string/object The actual value computed.
param_expected number/string/object The expected value.
param_note string Additional notes for the test (Optional).

Returns

(boolean): Returns true if the values are different, else false.

.true

expect.true((1 == 1))

checks if actual value is true.

Arguments

Argument Type Description
param_actual number/string The actual value computed.
param_note string Additional notes for the test (Optional).

Returns

(boolean): Returns true if the values are different, else false.

.false

expect.false((99 < 3))

checks if actual input is false.

Arguments

Argument Type Description
param_actual number/string/object The actual value computed.
param_note string Additional notes for the test (Optional).

Returns

(boolean): returns true if the value is false, else false

.undefined

expect.undefined("")

checks if actual is undefined ("").

Arguments

Argument Type Description
param_actual number/string The actual value computed.
param_note string Additional notes for the test (Optional).

Returns

(boolean): returns true if the value is "", else false

.group

expect.group("Object Tests")

appends the label to a group of following tests for logs and readability

Arguments

Argument Type Description
param_label string A human readable label prepend for the next test(s) in sequence

.label

expect.label("myInterestingLabel")

labels the following tests for logs and readability

Arguments

Argument Type Description
param_label string A human readable label for the next test(s) in sequence

.writeResultsToFile

expect.writeResultsToFile(".\myLogFile.tap")

Writes the report to a file and optionally opens the file.

Arguments

Argument Type Description
param_filepath string The path of the file where the report will be written. If not provided, the default logResultPath will be used.

Returns

(string): The report that was written to the file.

Exceptions

(Throws exception): If there is an error writing the report to the disk.

.report

expect.report()

returns the full test results. This should be used with to integrate with Continuous Integration (CI) Systems

Arguments

Does not accept any arguments.

Returns

(string): returns a string containing all the test results.

.fullReport

expect.fullReport()

Uses msgbox to display the results of all tests with details of any failures

Arguments

Does not accept any arguments.

Returns

(string): The generated full report message.