You can directly call m.pass()
or m.fail()
within a test case to mark it as passed or failed. Alternatively, roca
offers an assert
library (similar to Chai), available via m.assert
. These methods will call m.pass()
or m.fail()
for you.
Marks a unit test as passing. If the test case has previously been marked as failed, then this results in a no-op.
None.
None.
m.it("passes", sub()
m.pass()
end sub)
Marks a unit test as failing. Only the first failure encountered in a test case will be reported, and it will override any prior calls to m.pass
.
None.
None.
m.it("fails", sub()
m.fail()
end sub)
Compares two primitive values for equality.
None.
m.it("test case", sub()
m.assert.equal("foo", "foo", "whoops, these should be equal")
end sub)
Compares two values of any type for equality. It will recursively compare objects and arrays.
None.
m.it("test case", sub()
foo = { a: { b: ["c", "d"] }}
bar = { a: { b: ["c", "e"] }}
m.assert.deepEquals(foo, bar, "whoops, these should be equal")
end sub)
Verifies that a mock function has been called at least one time.
mock object
The mock function that was returned from _brs_.mockFunction
.
errorMessage string
optional
The error message to display if the mock was not called. If you don't pass an error message, one will automatically be created for you.
None.
m.it("test case", sub()
mock = _brs_.mockFunction("foo")
foo()
m.assert.hasBeenCalled(mock)
end sub)
Verifies that a mock function has been called a certain number of times.
mock object
The mock function that was returned from _brs_.mockFunction
.
errorMessage string
optional
The error message to display if the mock was not called. If you don't pass an error message, one will automatically be created for you.
None.
m.it("test case", sub()
mock = _brs_.mockFunction("foo")
foo()
foo()
m.assert.hasBeenCalledTimes(mock, 2)
end sub)
Verifies that a mock function has been called with certain arguments. Note that this will check against every call to the mock function.
mock object
The mock function that was returned from _brs_.mockFunction
.
errorMessage string
optional
The error message to display if the mock was not called. If you don't pass an error message, one will automatically be created for you.
None.
m.it("test case", sub()
mock = _brs_.mockFunction("foo")
foo("bar", 123, { baz: 456 })
m.assert.hasBeenCalledWith(mock, ["bar", 123, { baz: 456 }])
end sub)
Opposite of m.assert.equal
. Compares two primitive values.
None.
m.it("test case", sub()
m.assert.notEqual("foo", "not foo", "whoops, these should _not_ be equal")
end sub)
Checks to see if a boolean value is true
.
None.
m.it("test case", sub()
foo = true
m.assert.isTrue(foo, "whoops, foo should be true")
end sub)
Checks to see if a boolean value is false
.
None.
Usage:
m.it("test case", sub()
foo = false
m.assert.isFalse(foo, "whoops, foo should be false")
end sub)
Checks to see if a value is not invalid
.
None.
Usage:
m.it("test case", sub()
foo = {}
m.assert.isValid(foo, "whoops, foo should not be invalid")
end sub)
Checks to see if a value is invalid
.
None.
m.it("test case", sub()
foo = invalid
m.assert.isInvalid(foo, "whoops, foo should be invalid")
end sub)