Implementation of the expect
function is a bit similar to the jestjs.io one.
It can take any value, or mocked function name as an argument and you can call on it an assert function.
Checks equality of two values, or Node reference.
This does not work for object references (only Node).
it("should pass", function () as String
return expect(2).toBe(2)
end function)
Checks if value is invalid.
it("should pass", function () as String
return expect(Invalid).toBeInvalid()
end function)
Checks if value is valid.
it("should pass", function () as String
return expect(1).toBeValid()
end function)
Checks if value is true.
it("should pass", function () as String
return expect(true).toBeTrue()
end function)
Checks if value is false.
it("should pass", function () as String
return expect(false).toBeFalse()
end function)
Checks values equality. For primitive values works the same as toBe.
Examples:
For AssociativeArray
it("should pass", function () as String
return expect({ a: 2 }).toEqual({ a: 2 })
end function)
For Nodes
it("should pass", function () as String
nodeA = CreateNode("roSGNode", "Rectangle")
nodeA.id = "asd"
nodeB = CreateNode("roSGNode", "Rectangle")
nodeB.id = "asd"
return expect(nodeA).toEqual(nodeB)
end function)
Checks if Array/AssociativeArray/Node contains the expected value/subset/node
Examples:
For Array entries
it("should pass", function () as String
return expect(["a", "b"]).toContain("a")
end function)
For AssociativeArray subset
it("should pass", function () as String
return expect({ a: 2, b: 5 }).toContain({ a: 2 })
end function)
For Nodes fields
it("should pass", function () as String
node = CreateNode("roSGNode", "Rectangle")
node.id = "asd"
return expect(node).toContain({ id: "asd" })
end function)
For Nodes children
it("should pass", function () as String
parent = CreateNode("roSGNode", "Rectangle")
child = CreateNode("roSGNode", "Rectangle")
parent.appendChild(child)
return expect(parent).toContain(child)
end function)
Checks if AssociativeArray contains given key.
it("should pass", function () as String
return expect({ a: 2 }).toHaveKey("a")
end function)
Checks if AssociativeArray contains given keys.
it("should pass", function () as String
return expect({ a: 2, b: "asd" }).toHaveKeys(["a", "b"])
end function)
Checks if Array or AssociativeArray has given lenght/count.
it("should pass", function () as String
return expect({ a: 2, b: "asd" }).toHaveLength(2)
end function)
Checks if mocked function was called at least once.
' @mock /path/to/functionName
it("should pass", function () as String
return expect("functionName").toHaveBeenCalled()
end function)
Checks if mocked function was called given times.
' @mock /path/to/functionName
it("should pass", function () as String
return expect("functionName").toHaveBeenCalledTimes(1)
end function)
Checks if mocked function was called with given arguments.
Checks if mocked function was called given times.
' @mock /path/to/functionName
it("should pass", function () as String
return expect("functionName").toHaveBeenCalledWith({ a: 2 })
end function)
By default, this function is not in strict mode. So it will validate only against given arguments. With strict mode, it checks if all arguments are identical So this will throw an error.
' @mock /path/to/functionWithThreeArguments
it("should pass", function () as String
return expect("functionWithThreeArguments").toHaveBeenCalledWith({ a: 2, b: 3 }, { strict: true })
end function)
Checks if mocked function last call was with given arguments.
' @mock /path/to/functionName
it("should pass", function () as String
return expect("functionName").toHaveBeenLastCalledWith({ a: 2 })
end function)
By default, this function is not in strict mode. So it will validate only against given arguments. With strict mode, it checks if all arguments are identical So this will throw an error.
' @mock /path/to/functionWithThreeArguments
it("should pass", function () as String
return expect("functionWithThreeArguments").toHaveBeenLastCalledWith({ a: 2, b: 3 }, { strict: true })
end function)
Checks if mocked function nth, given, call was executed with given arguments.
' @mock /path/to/functionName
it("should pass", function () as String
return expect("functionName").toHaveBeenNthCalledWith(1, { a: 2 })
end function)
By default, this function is not in strict mode. So it will validate only against given arguments. With strict mode, it checks if all arguments are identical So this will throw an error.
' @mock /path/to/functionWithThreeArguments
it("should pass", function () as String
return expect("functionWithThreeArguments").toHaveBeenNthCalledWith(1, { a: 2, b: 3 }, { strict: true })
end function)
Checks if the function throws an exception.
it("should pass", function () as String
return expect(functionThatThrow).toThrow("Error message")
end function)
Check the opposite of the assert function.
it("should pass", function () as String
return expect(1)not.toBe(4)
end function)