Is it(), expect(), and describe() functions real functions? And if they are how and when do I use them?

I am just really confused. I was checking roact’s source code, and I found scripts that have “.spec” at the end of their name ([scriptName].spec). The scripts with .spec at the end of their name returned a function, with undefined functions inside of that function. Undefined functions such “it”, “describe”, “expect”, were some of the functions used. When I tried to play around with the functions, they just didn’t work.

snippet from assign.spec:

it("should accept zero additional tables", function()
		local input = {}
		local result = assign(input)

		expect(input).to.equal(result)
	end)

Now let me remind you that the corresponding script on roblox studio highlights them as a undefined function, and trying to call these modules result in an error. Is there any explanation to this?

image

Please explain how this works, because I am very confused.

The functions you are trying to use are the functions of a module script, which you define inside them. They are not global but defined in a module script.

local module = {}

function module.Print()
    print("Hi!")
end

return module

And you can require this module script in another script.

local module = require(game:GetService("ReplicatedStorage").ModuleScript)

module.Print()

It was probably a custom function they made in that script. I’ve seen things like this before where people do local function functionName or something like that to use within their script. So no, these are not “real” functions. They are not part of Roblox’s built-in functions.

That’s not what I’m talking about at all. There are no refrences of that said function. You run this as such:

return function()
    describe("truth", function()
      print("This function is not defined in ANY way")
    end)
end

github source:
Check for yourself.

Also, even if these functions are not real, why would a library like Roact place that in to begin with?

You have found Roact’s test cases. Roact uses TestEZ to make sure after any update their library still works correctly. These tests basically try and simulate an action to make sure it still returns the correct info.
Here is the github link GitHub - Roblox/testez: BDD-style test and assertion library for Roblox Lua

And here is the API API Reference - TestEZ Documentation

Additionally if you are looking to implement tests into your own game, there is a neat little plugin that can help you linked here.

4 Likes