SyntaxGameServer/RCCService2018/content/LuaPackages/PurchasePrompt/makeActionCreator.spec.lua

47 lines
1.3 KiB
Lua

return function()
local makeActionCreator = require(script.Parent.makeActionCreator)
describe("the generated action creator", function()
it("should throw if given an invalid arguments", function()
expect(function()
makeActionCreator(100)
end).to.throw()
expect(function()
makeActionCreator("Test", 12)
end).to.throw()
end)
it("should generate a callable table with a 'name' field", function()
local actionCreator = makeActionCreator("Action")
expect(type(actionCreator)).to.equal("table")
expect(actionCreator.name).to.equal("Action")
expect(actionCreator).never.to.throw()
end)
end)
describe("the action object generated by the action creator", function()
it("should expect a matching number of inputs", function()
local actionWithFields = makeActionCreator("AddItem", "id", "title")
expect(function()
actionWithFields(10, "Apple", "extra arg")
end).to.throw()
expect(function()
actionWithFields(10)
end).to.throw()
expect(function()
actionWithFields(10, "Orange")
end).never.to.throw()
end)
it("should correctly count trailing nils", function()
local actionWithFields = makeActionCreator("SetProperty", "value", "default")
expect(function()
actionWithFields("1", nil)
end).never.to.throw()
end)
end)
end