From 974f1ea9ad0741d11ca67adb4223236bcd6f353f Mon Sep 17 00:00:00 2001 From: RoFlection Bot Date: Thu, 25 Feb 2021 14:21:44 -0800 Subject: [PATCH] Import roblox-jest and use new expect in array tests (#35) --- Packages/.robloxrc | 2 +- bin/ci.sh | 2 + bin/spec.lua | 11 +++--- rotriever.toml | 4 +- src/Array/__tests__/concat.spec.lua | 52 +++++++++++++------------- src/Array/__tests__/every.spec.lua | 50 ++++++++++++++----------- src/Array/__tests__/filter.spec.lua | 30 ++++++++------- src/Array/__tests__/find.spec.lua | 16 ++++---- src/Array/__tests__/findIndex.spec.lua | 24 ++++++------ src/Array/__tests__/from.spec.lua | 21 +++++++---- src/Array/__tests__/indexOf.spec.lua | 33 +++++++++------- src/Array/__tests__/isArray.spec.lua | 48 +++++++++++++----------- src/Array/__tests__/join.spec.lua | 34 +++++++++++------ src/Array/__tests__/map.spec.lua | 35 +++++++++-------- src/Array/__tests__/reduce.spec.lua | 40 +++++++++++--------- src/Array/__tests__/shift.spec.lua | 24 +++++++----- src/Array/__tests__/slice.spec.lua | 32 ++++++++-------- src/Array/__tests__/some.spec.lua | 43 +++++++++++---------- src/Array/__tests__/sort.spec.lua | 29 +++++++------- src/Array/__tests__/splice.spec.lua | 45 +++++++++++----------- src/Array/reduce.lua | 2 +- src/Array/some.lua | 2 +- test-model.project.json | 8 ++-- 23 files changed, 328 insertions(+), 259 deletions(-) diff --git a/Packages/.robloxrc b/Packages/.robloxrc index fb31f2e..86944c9 100644 --- a/Packages/.robloxrc +++ b/Packages/.robloxrc @@ -5,4 +5,4 @@ "lint": { "*": "disabled" } -} \ No newline at end of file +} diff --git a/bin/ci.sh b/bin/ci.sh index 0776b98..6cdf293 100755 --- a/bin/ci.sh +++ b/bin/ci.sh @@ -4,6 +4,8 @@ set -ex echo "Build project" rojo build test-model.project.json --output model.rbxmx +echo "Remove .robloxrc from jest-roblox" +rm -f Packages/_Index/roblox_jest-roblox/jest-roblox/.robloxrc echo "Run static analysis" roblox-cli analyze test-model.project.json echo "Run tests in DEV" diff --git a/bin/spec.lua b/bin/spec.lua index 8bca70b..5786c1f 100644 --- a/bin/spec.lua +++ b/bin/spec.lua @@ -1,13 +1,14 @@ local ProcessService = game:GetService("ProcessService") local Root = script.Parent.LuauPolyfillTestModel --- Load RoactNavigation source into Packages folder so it's next to Roact as expected -local TestEZ = require(Root.Packages.Dev.TestEZ) +local Packages = Root.Packages +-- Load JestRoblox source into Packages folder so it's next to Roact as expected +local JestRoblox = require(Root.Packages.Dev.JestRoblox) -- Run all tests, collect results, and report to stdout. -local result = TestEZ.TestBootstrap:run( - { Root.LuauPolyfill }, - TestEZ.Reporters.TextReporter +local result = JestRoblox.TestBootstrap:run( + { Packages.LuauPolyfill }, + JestRoblox.Reporters.TextReporter ) if result.failureCount == 0 then diff --git a/rotriever.toml b/rotriever.toml index 27e9c04..efb6f54 100644 --- a/rotriever.toml +++ b/rotriever.toml @@ -6,6 +6,4 @@ content_root = "src" default_alias = "LuauPolyfill" [dev_dependencies] -# TODO: Flip over to the jest-roblox repo whenever a release is ready, or if -# there's a particular git branch we'd like to use -TestEZ = "github.com/roblox/testez@0.4.1" +JestRoblox = "github.com/roblox/jest-roblox@0.6.0" diff --git a/src/Array/__tests__/concat.spec.lua b/src/Array/__tests__/concat.spec.lua index 2883784..fb08153 100644 --- a/src/Array/__tests__/concat.spec.lua +++ b/src/Array/__tests__/concat.spec.lua @@ -1,59 +1,59 @@ -- Some tests are adapted from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat return function() - local concat = require(script.Parent.Parent.concat) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local concat = require(Array.concat) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("concatenate arrays with single values", function() - local expect: any = expect - expect(concat({ 1 })).toEqual({ 1 }) - expect(concat({ 1 }, { 2 })).toEqual({ 1, 2 }) - expect(concat({ 1 }, { 2 }, { 3 })).toEqual({ 1, 2, 3 }) + jestExpect(concat({ 1 })).toEqual({ 1 }) + jestExpect(concat({ 1 }, { 2 })).toEqual({ 1, 2 }) + jestExpect(concat({ 1 }, { 2 }, { 3 })).toEqual({ 1, 2, 3 }) end) it("concatenate arrays with multiple values", function() - local expect: any = expect - expect(concat({ 1 }, { 2, 3 })).toEqual({ 1, 2, 3 }) - expect(concat({ 1, 2 }, { 3 })).toEqual({ 1, 2, 3 }) - expect(concat({ 1, 2 }, { 3, 4 })).toEqual({ 1, 2, 3, 4 }) - expect(concat({ 1, 2 }, { 3, 4 }, { 5, 6 })).toEqual({ 1, 2, 3, 4, 5, 6 }) + jestExpect(concat({ 1 }, { 2, 3 })).toEqual({ 1, 2, 3 }) + jestExpect(concat({ 1, 2 }, { 3 })).toEqual({ 1, 2, 3 }) + jestExpect(concat({ 1, 2 }, { 3, 4 })).toEqual({ 1, 2, 3, 4 }) + jestExpect(concat({ 1, 2 }, { 3, 4 }, { 5, 6 })).toEqual({ 1, 2, 3, 4, 5, 6 }) end) it("concatenate values", function() - local expect: any = expect - expect(concat(1)).toEqual({ 1 }) - expect(concat(1, 2)).toEqual({ 1, 2 }) - expect(concat(1, 2, 3)).toEqual({ 1, 2, 3 }) - expect(concat(1, 2, 3, 4)).toEqual({ 1, 2, 3, 4 }) + jestExpect(concat(1)).toEqual({ 1 }) + jestExpect(concat(1, 2)).toEqual({ 1, 2 }) + jestExpect(concat(1, 2, 3)).toEqual({ 1, 2, 3 }) + jestExpect(concat(1, 2, 3, 4)).toEqual({ 1, 2, 3, 4 }) end) it("concatenate values and arrays combination", function() - local expect: any = expect - expect(concat(1, { 2 })).toEqual({ 1, 2 }) - expect(concat({ 1 }, 2)).toEqual({ 1, 2 }) - expect(concat({ 1 }, 2, { 3 })).toEqual({ 1, 2, 3 }) - expect(concat({ 1, 2 }, 3, { 4 })).toEqual({ 1, 2, 3, 4 }) + jestExpect(concat(1, { 2 })).toEqual({ 1, 2 }) + jestExpect(concat({ 1 }, 2)).toEqual({ 1, 2 }) + jestExpect(concat({ 1 }, 2, { 3 })).toEqual({ 1, 2, 3 }) + jestExpect(concat({ 1, 2 }, 3, { 4 })).toEqual({ 1, 2, 3, 4 }) end) it("concatenates values to an array", function() - local expect: any = expect local letters = { "a", "b", "c" } local alphaNumeric = concat(letters, 1, { 2, 3 }) - expect(alphaNumeric).toEqual({ "a", "b", "c", 1, 2, 3 }) + jestExpect(alphaNumeric).toEqual({ "a", "b", "c", 1, 2, 3 }) end) it("concatenates nested arrays", function() - local expect: any = expect local num1 = { { 1 } } local num2 = { 2, { 3 } } local numbers = concat(num1, num2) - expect(numbers).toEqual({ { 1 }, 2, { 3 } }) + jestExpect(numbers).toEqual({ { 1 }, 2, { 3 } }) end) if _G.__DEV__ then it("throws when an object-like table value is passed", function() - expect(function() + jestExpect(function() concat({1, 2}, { a = true }) - end).to.throw("Array.concat(...) only works with array-like tables but it received an object-like table") + end).toThrow("Array.concat(...) only works with array-like tables but it received an object-like table") end) end end diff --git a/src/Array/__tests__/every.spec.lua b/src/Array/__tests__/every.spec.lua index f055e86..a261659 100644 --- a/src/Array/__tests__/every.spec.lua +++ b/src/Array/__tests__/every.spec.lua @@ -5,70 +5,76 @@ -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every return function() - local every = require(script.Parent.Parent.every) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local every = require(Array.every) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("Invalid argument", function() - expect(function() + jestExpect(function() every(nil, function() end) - end).to.throw() - expect(function() + end).toThrow() + jestExpect(function() every({0, 1}, nil) - end).to.throw() + end).toThrow() end) it("Testing size of all array elements", function() - local isBigEnough = function(element, index, array) + local isBigEnough = function(element, index, array) return element >= 10 end - expect(every( + jestExpect(every( {12, 5, 8, 130, 44}, isBigEnough - )).to.equal(false) - expect(every( + )).toEqual(false) + jestExpect(every( {12, 54, 18, 130, 44}, isBigEnough - )).to.equal(true) + )).toEqual(true) end) it("Modifying initial array", function() local arr = {1, 2, 3, 4} local expected = {1, 1, 2} - expect(every( + jestExpect(every( arr, function(elem, index, a) a[index + 1] -= 1 - expect(a[index]).to.equal(expected[index]) + jestExpect(a[index]).toEqual(expected[index]) return elem < 2 end - )).to.equal(false) - expect(arr).toEqual({1, 1, 2, 3}) + )).toEqual(false) + jestExpect(arr).toEqual({1, 1, 2, 3}) end) it("Appending to initial array", function() local arr = {1, 2, 3} local expected = {1, 2, 3} - expect(every( + jestExpect(every( arr, function(elem, index, a) table.insert(a, "new") - expect(a[index]).to.equal(expected[index]) + jestExpect(a[index]).toEqual(expected[index]) return elem < 4 end - )).to.equal(true) - expect(arr).toEqual({1, 2, 3, "new", "new", "new"}) + )).toEqual(true) + jestExpect(arr).toEqual({1, 2, 3, "new", "new", "new"}) end) it("Deleting from inital array", function() local arr = {1, 2, 3, 4} local expected = {1, 2} - expect(every( + jestExpect(every( arr, function(elem, index, a) table.remove(a) - expect(a[index]).to.equal(expected[index]) + jestExpect(a[index]).toEqual(expected[index]) return elem < 4 end - )).to.equal(true) - expect(arr).toEqual({1, 2}) + )).toEqual(true) + jestExpect(arr).toEqual({1, 2}) end) end \ No newline at end of file diff --git a/src/Array/__tests__/filter.spec.lua b/src/Array/__tests__/filter.spec.lua index ef4ef7d..d40b1cd 100644 --- a/src/Array/__tests__/filter.spec.lua +++ b/src/Array/__tests__/filter.spec.lua @@ -1,13 +1,17 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` --!nocheck -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter return function() - local filter = require(script.Parent.Parent.filter) - local isFinite = require(script.Parent.Parent.Parent.Number.isFinite) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local filter = require(Array.filter) + local isFinite = require(LuauPolyfill.Number.isFinite) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("Filtering out all small values", function() local isBigEnough = function(value) @@ -15,7 +19,7 @@ return function() end local filtered = filter({12, 5, 8, 130, 44}, isBigEnough) - expect(filtered).toEqual({12, 130, 44}) + jestExpect(filtered).toEqual({12, 130, 44}) end) it("Find all prime numbers in an array", function() @@ -34,7 +38,7 @@ return function() {-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, isPrime ) - expect(filtered).toEqual({2, 3, 5, 7, 11, 13}) + jestExpect(filtered).toEqual({2, 3, 5, 7, 11, 13}) end) it("Filtering invalid entries from JSON", function() @@ -61,10 +65,10 @@ return function() end local arrByID = filter(arr, filterByID) - expect(arrByID).toEqual( + jestExpect(arrByID).toEqual( {{ id = 15 }, { id = -1 }, { id = 3 }, { id = 12.2 }} ) - expect(invalidEntries).to.equal(5) + jestExpect(invalidEntries).toEqual(5) end) it("Searching in array", function() @@ -75,8 +79,8 @@ return function() end) end - expect(filterItems(fruits, "ap")).toEqual({"apple", "grapes"}) - expect(filterItems(fruits, "an")).toEqual({"banana", "mango", "orange"}) + jestExpect(filterItems(fruits, "ap")).toEqual({"apple", "grapes"}) + jestExpect(filterItems(fruits, "an")).toEqual({"banana", "mango", "orange"}) end) describe("Affecting Initial Array", function() @@ -94,7 +98,7 @@ return function() end ) - expect(modifiedWords).toEqual({"spray"}) + jestExpect(modifiedWords).toEqual({"spray"}) end) it("Appending to initial array", function() @@ -108,7 +112,7 @@ return function() end ) - expect(modifiedWords).toEqual({"spray", "limit", "elite"}) + jestExpect(modifiedWords).toEqual({"spray", "limit", "elite"}) end) it("Deleting from initial array", function() @@ -122,7 +126,7 @@ return function() end ) - expect(modifiedWords).toEqual({"spray", "limit"}) + jestExpect(modifiedWords).toEqual({"spray", "limit"}) end) end) end \ No newline at end of file diff --git a/src/Array/__tests__/find.spec.lua b/src/Array/__tests__/find.spec.lua index 2d214f6..55f5413 100644 --- a/src/Array/__tests__/find.spec.lua +++ b/src/Array/__tests__/find.spec.lua @@ -1,7 +1,12 @@ return function() local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent local find = require(Array.find) + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + local function returnTrue() return true end @@ -11,18 +16,18 @@ return function() end it("returns nil if the array is empty", function() - expect(find({}, returnTrue)).to.equal(nil) + jestExpect(find({}, returnTrue)).toEqual(nil) end) it("returns nil if the predicate is always false", function() - expect(find({1, 2, 3}, returnFalse)).to.equal(nil) + jestExpect(find({1, 2, 3}, returnFalse)).toEqual(nil) end) it("returns the first element where the predicate is true", function() local result = find({3, 4, 5, 6}, function(element) return element % 2 == 0 end) - expect(result).to.equal(4) + jestExpect(result).toEqual(4) end) it("passes the element, its index and the array to the predicate", function() @@ -31,9 +36,6 @@ return function() find(array, function(...) arguments = {...} end) - expect(#arguments).to.equal(3) - expect(arguments[1]).to.equal("foo") - expect(arguments[2]).to.equal(1) - expect(arguments[3]).to.equal(array) + jestExpect(arguments).toEqual({"foo", 1, array}) end) end diff --git a/src/Array/__tests__/findIndex.spec.lua b/src/Array/__tests__/findIndex.spec.lua index 6dba685..404bb3e 100644 --- a/src/Array/__tests__/findIndex.spec.lua +++ b/src/Array/__tests__/findIndex.spec.lua @@ -1,8 +1,13 @@ --!nonstrict return function() local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent local findIndex = require(Array.findIndex) + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + local function returnTrue() return true end @@ -12,18 +17,18 @@ return function() end it("returns -1 if the array is empty", function() - expect(findIndex({}, returnTrue)).to.equal(-1) + jestExpect(findIndex({}, returnTrue)).toEqual(-1) end) it("returns -1 if the predicate is always false", function() - expect(findIndex({1, 2, 3}, returnFalse)).to.equal(-1) + jestExpect(findIndex({1, 2, 3}, returnFalse)).toEqual(-1) end) it("returns the first index where the predicate is true", function() local result = findIndex({3, 4, 5, 6}, function(element) return element % 2 == 0 end) - expect(result).to.equal(2) + jestExpect(result).toEqual(2) end) it("passes the element, its index and the array to the predicate", function() @@ -32,10 +37,7 @@ return function() findIndex(array, function(...) arguments = {...} end) - expect(#arguments).to.equal(3) - expect(arguments[1]).to.equal("foo") - expect(arguments[2]).to.equal(1) - expect(arguments[3]).to.equal(array) + jestExpect(arguments).toEqual({"foo", 1, array}) end) -- the following tests were taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex @@ -44,7 +46,7 @@ return function() local function isLargeNumber(element) return element > 13 end - expect(findIndex(array1, isLargeNumber)).to.equal(4) + jestExpect(findIndex(array1, isLargeNumber)).toEqual(4) end) it("returns first prime element", function() @@ -58,13 +60,13 @@ return function() return num > 1 end - expect(findIndex({4, 6, 8, 9, 12}, isPrime)).to.equal(-1) - expect(findIndex({4, 6, 7, 9, 12}, isPrime)).to.equal(3) + jestExpect(findIndex({4, 6, 8, 9, 12}, isPrime)).toEqual(-1) + jestExpect(findIndex({4, 6, 7, 9, 12}, isPrime)).toEqual(3) end) it("returns first matching string", function() local fruits = {"apple", "banana", "cantaloupe", "blueberries", "grapefruit"} - expect(findIndex(fruits, function(fruit) return fruit == "blueberries" end)).to.equal(4) + jestExpect(findIndex(fruits, function(fruit) return fruit == "blueberries" end)).toEqual(4) end) end diff --git a/src/Array/__tests__/from.spec.lua b/src/Array/__tests__/from.spec.lua index ddf8ec8..d0d3b88 100644 --- a/src/Array/__tests__/from.spec.lua +++ b/src/Array/__tests__/from.spec.lua @@ -3,37 +3,42 @@ -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from return function() local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent local from = require(Array.from) + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + it("creates a array of characters given a string", function() - expect(from("bar")).toEqual({"b", "a", "r"}) + jestExpect(from("bar")).toEqual({"b", "a", "r"}) end) it("creates an array from another array", function() - expect(from({"foo", "bar"})).toEqual({"foo", "bar"}) + jestExpect(from({"foo", "bar"})).toEqual({"foo", "bar"}) end) it("returns an empty array given a number", function() - expect(from(10)).toEqual({}) + jestExpect(from(10)).toEqual({}) end) it("returns an empty array given an empty table", function() - expect(from({})).toEqual({}) + jestExpect(from({})).toEqual({}) end) it("returns an empty array given a map-like table", function() - expect(from({foo = "bar"})).toEqual({}) + jestExpect(from({foo = "bar"})).toEqual({}) end) it("throws when given nil", function() expect(function() from(nil) - end).to.throw("cannot create array from a nil value") + end).toThrow("cannot create array from a nil value") end) describe("with mapping function", function() it("maps each character", function() - expect( + jestExpect( from("bar", function(character, index) return character .. index end) @@ -41,7 +46,7 @@ return function() end) it("maps each element of the array", function() - expect( + jestExpect( from({10, 20}, function(element, index) return element + index end) diff --git a/src/Array/__tests__/indexOf.spec.lua b/src/Array/__tests__/indexOf.spec.lua index 07a5a45..8dcb2a5 100644 --- a/src/Array/__tests__/indexOf.spec.lua +++ b/src/Array/__tests__/indexOf.spec.lua @@ -1,38 +1,45 @@ -- Tests partially based on examples from: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf return function() - local indexOf = require(script.Parent.Parent.indexOf) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local indexOf = require(Array.indexOf) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + local beasts = { "ant", "bison", "camel", "duck", "bison" } it("returns the index of the first occurrence of an element", function() - expect(indexOf(beasts, "bison")).to.equal(2) + jestExpect(indexOf(beasts, "bison")).toEqual(2) end) it("begins at the start index when provided", function() - expect(indexOf(beasts, "bison", 3)).to.equal(5) + jestExpect(indexOf(beasts, "bison", 3)).toEqual(5) end) it("returns -1 when the value isn't present", function() - expect(indexOf(beasts, "giraffe")).to.equal(-1) + jestExpect(indexOf(beasts, "giraffe")).toEqual(-1) end) it("returns -1 when the fromIndex is too large", function() - expect(indexOf(beasts, "camel", 6)).to.equal(-1) + jestExpect(indexOf(beasts, "camel", 6)).toEqual(-1) end) it("accepts a negative fromIndex, and subtracts it from the total length", function() - expect(indexOf(beasts, "bison", -4)).to.equal(2) - expect(indexOf(beasts, "bison", -2)).to.equal(5) - expect(indexOf(beasts, "ant", -2)).to.equal(-1) + jestExpect(indexOf(beasts, "bison", -4)).toEqual(2) + jestExpect(indexOf(beasts, "bison", -2)).toEqual(5) + jestExpect(indexOf(beasts, "ant", -2)).toEqual(-1) end) it("accepts a 0 fromIndex (special case for Lua's 1-index arrays) and starts at the end", function() - expect(indexOf(beasts, "bison", 0)).to.equal(5) + jestExpect(indexOf(beasts, "bison", 0)).toEqual(5) end) it("starts at the beginning when it receives a too-large negative fromIndex", function() - expect(indexOf(beasts, "bison", -10)).to.equal(2) - expect(indexOf(beasts, "ant", -10)).to.equal(1) + jestExpect(indexOf(beasts, "bison", -10)).toEqual(2) + jestExpect(indexOf(beasts, "ant", -10)).toEqual(1) end) it("uses strict equality", function() @@ -42,7 +49,7 @@ return function() { x = 2 }, { x = 3 }, } - expect(indexOf(objects, { x = 2 })).to.equal(-1) - expect(indexOf(objects, firstObject)).to.equal(1) + jestExpect(indexOf(objects, { x = 2 })).toEqual(-1) + jestExpect(indexOf(objects, firstObject)).toEqual(1) end) end \ No newline at end of file diff --git a/src/Array/__tests__/isArray.spec.lua b/src/Array/__tests__/isArray.spec.lua index 83d9283..bec9437 100644 --- a/src/Array/__tests__/isArray.spec.lua +++ b/src/Array/__tests__/isArray.spec.lua @@ -1,56 +1,62 @@ -- Tests partially based on examples from: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray return function() - local isArray = require(script.Parent.Parent.isArray) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local isArray = require(Array.isArray) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("returns false for non-tables", function() - expect(isArray(nil)).to.equal(false) - expect(isArray(1)).to.equal(false) - expect(isArray("hello")).to.equal(false) - expect(isArray(function() end)).to.equal(false) - expect(isArray(newproxy(false))).to.equal(false) + jestExpect(isArray(nil)).toEqual(false) + jestExpect(isArray(1)).toEqual(false) + jestExpect(isArray("hello")).toEqual(false) + jestExpect(isArray(function() end)).toEqual(false) + jestExpect(isArray(newproxy(false))).toEqual(false) end) it("returns false for tables with non-number keys", function() - expect(isArray({ hello = 1 })).to.equal(false) - expect(isArray({ [function() end] = 1 })).to.equal(false) - expect(isArray({ [newproxy(false)] = 1 })).to.equal(false) + jestExpect(isArray({ hello = 1 })).toEqual(false) + jestExpect(isArray({ [function() end] = 1 })).toEqual(false) + jestExpect(isArray({ [newproxy(false)] = 1 })).toEqual(false) end) it("returns false for a table with non-integer key", function() - expect(isArray({ [0.5] = true })).to.equal(false) + jestExpect(isArray({ [0.5] = true })).toEqual(false) end) it("returns false for a table with a key equal to zero", function() - expect(isArray({ [0] = true })).to.equal(false) + jestExpect(isArray({ [0] = true })).toEqual(false) end) it("returns true for an empty table", function() - expect(isArray({})).to.equal(true) + jestExpect(isArray({})).toEqual(true) end) it("returns false for sparse arrays", function() - expect(isArray({ + jestExpect(isArray({ [1] = "1", [3] = "3", - })).to.equal(false) - expect(isArray({ + })).toEqual(false) + jestExpect(isArray({ [2] = "2", [3] = "3", - })).to.equal(false) + })).toEqual(false) end) it("returns false for tables with non-positive-number keys", function() - expect(isArray({ + jestExpect(isArray({ [-2] = "-2", [2] = "2", [3] = "3", - })).to.equal(false) + })).toEqual(false) end) it("returns true for valid arrays", function() - expect(isArray({ "a", "b", "c" })).to.equal(true) - expect(isArray({ 1, 2, 3 })).to.equal(true) - expect(isArray({ 1, "b", function() end })).to.equal(true) + jestExpect(isArray({ "a", "b", "c" })).toEqual(true) + jestExpect(isArray({ 1, 2, 3 })).toEqual(true) + jestExpect(isArray({ 1, "b", function() end })).toEqual(true) end) end diff --git a/src/Array/__tests__/join.spec.lua b/src/Array/__tests__/join.spec.lua index 8f280d8..7692af5 100644 --- a/src/Array/__tests__/join.spec.lua +++ b/src/Array/__tests__/join.spec.lua @@ -1,26 +1,36 @@ return function() - local join = require(script.Parent.Parent.join) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local join = require(Array.join) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect describe("Join", function() local arr = { "Wind", "Water", "Fire" } + it("should join strings arrays without specified separator", function() - expect(join(arr)).to.equal("Wind,Water,Fire") + jestExpect(join(arr)).toEqual("Wind,Water,Fire") end) + it("should join strings arrays with specified separator", function() - expect(join(arr, ", ")).to.equal("Wind, Water, Fire") - expect(join(arr, " + ")).to.equal("Wind + Water + Fire") - expect(join(arr, "")).to.equal("WindWaterFire") + jestExpect(join(arr, ", ")).toEqual("Wind, Water, Fire") + jestExpect(join(arr, " + ")).toEqual("Wind + Water + Fire") + jestExpect(join(arr, "")).toEqual("WindWaterFire") end) + it("should join empty array", function() - expect(join({})).to.equal("") - expect(join({}, ", ")).to.equal("") - expect(join({}, " + ")).to.equal("") - expect(join({}, "")).to.equal("") + jestExpect(join({})).toEqual("") + jestExpect(join({}, ", ")).toEqual("") + jestExpect(join({}, " + ")).toEqual("") + jestExpect(join({}, "")).toEqual("") end) + it("should not add separator for array with single element", function() - expect(join({"foo"}, ", ")).to.equal("foo") - expect(join({"foo"}, " + ")).to.equal("foo") - expect(join({"foo"}, "")).to.equal("foo") + jestExpect(join({"foo"}, ", ")).toEqual("foo") + jestExpect(join({"foo"}, " + ")).toEqual("foo") + jestExpect(join({"foo"}, "")).toEqual("foo") end) end) end diff --git a/src/Array/__tests__/map.spec.lua b/src/Array/__tests__/map.spec.lua index b8d3b0f..083f826 100644 --- a/src/Array/__tests__/map.spec.lua +++ b/src/Array/__tests__/map.spec.lua @@ -1,19 +1,24 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` ---!nocheck - -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map return function() - local map = require(script.Parent.Parent.map) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local map = require(Array.map) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("Invalid argument", function() - expect(function() - map(nil, function() end) - end).to.throw() - expect(function() - map({0, 1}, nil) - end).to.throw() + -- roblox-cli analyze fails because map is called with an + -- invalid argument, so it needs to be cast to any + local mapAny: any = map + jestExpect(function() + mapAny(nil, function() end) + end).toThrow() + jestExpect(function() + mapAny({0, 1}, nil) + end).toThrow() end) it("Mapping an array of numbers to an array of square roots", function() @@ -21,8 +26,8 @@ return function() local roots = map(numbers, function(num) return math.sqrt(num) end) - expect(numbers).toEqual({1, 4, 9}) - expect(roots).toEqual({1, 2, 3}) + jestExpect(numbers).toEqual({1, 4, 9}) + jestExpect(roots).toEqual({1, 2, 3}) end) it("Using map to reformat objects in an array", function() @@ -37,7 +42,7 @@ return function() return rObj end) -- // reformattedArray is now [{1: 10}, {2: 20}, {3: 30}] - expect(reformattedArray).toEqual({ + jestExpect(reformattedArray).toEqual({ {[1] = 10}, {[2] = 20}, {[3] = 30}, @@ -49,6 +54,6 @@ return function() local doubles = map(numbers, function(num) return num * 2 end) - expect(doubles).toEqual({2, 8, 18}) + jestExpect(doubles).toEqual({2, 8, 18}) end) end \ No newline at end of file diff --git a/src/Array/__tests__/reduce.spec.lua b/src/Array/__tests__/reduce.spec.lua index eb06bf0..e4872d9 100644 --- a/src/Array/__tests__/reduce.spec.lua +++ b/src/Array/__tests__/reduce.spec.lua @@ -1,33 +1,39 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` ---!nocheck - -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce return function() - local reduce = require(script.Parent.Parent.reduce) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local reduce = require(Array.reduce) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + it("Invalid argument", function() - expect(function() - reduce(nil, function() end) - end).to.throw() - expect(function() - reduce({0, 1}, nil) - end).to.throw() + -- roblox-cli analyze fails because map is called with an + -- invalid argument, so it needs to be cast to any + local reduceAny: any = reduce + jestExpect(function() + reduceAny(nil, function() end) + end).toThrow() + jestExpect(function() + reduceAny({0, 1}, nil) + end).toThrow() end) it("Sum all the values of an array", function() - expect( + jestExpect( reduce( {1, 2, 3, 4}, function(accumulator, currentValue) return accumulator + currentValue end ) - ).to.equal(10) + ).toEqual(10) end) it("Sum of values in an object array", function() - expect( + jestExpect( reduce( { { x = 1 }, { x = 2 }, { x = 3 } }, function(accumulator, currentValue) @@ -35,7 +41,7 @@ return function() end, 0 ) - ).to.equal(6) + ).toEqual(6) end) it("Counting instances of values in an object", function() @@ -52,7 +58,7 @@ return function() end, {} ) - expect(reduced).toEqual({ + jestExpect(reduced).toEqual({ Alice = 2, Bob = 1, Tiff = 1, @@ -78,7 +84,7 @@ return function() end, {} ) - expect(reduced).toEqual({ + jestExpect(reduced).toEqual({ [20] = { { name = "Max", age = 20 }, { name = "Jane", age = 20 }, diff --git a/src/Array/__tests__/shift.spec.lua b/src/Array/__tests__/shift.spec.lua index 2d65983..afdd900 100644 --- a/src/Array/__tests__/shift.spec.lua +++ b/src/Array/__tests__/shift.spec.lua @@ -1,24 +1,28 @@ ---!nocheck -- tests based on the examples provided on MDN web docs: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift return function() local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent local shift = require(Array.shift) + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + it("shifts three element array", function() local array1 = {1, 2, 3} local firstElement = shift(array1) - expect(array1).toEqual({2, 3}) - expect(firstElement).to.equal(1) + jestExpect(array1).toEqual({2, 3}) + jestExpect(firstElement).toEqual(1) end) it("removes an element from an array", function() local myFish = {"angel", "clown", "mandarin", "surgeon"} local shifted = shift(myFish) - expect(myFish).toEqual({"clown", "mandarin", "surgeon"}) - expect(shifted).to.equal("angel") + jestExpect(myFish).toEqual({"clown", "mandarin", "surgeon"}) + jestExpect(shifted).toEqual("angel") end) it("shifts in a loop", function() @@ -28,24 +32,24 @@ return function() while name do nameString = nameString .. " " .. name - name = shift(names) + name = shift(names) end - expect(nameString).to.equal(" Andrew Edward Paul Chris John") + jestExpect(nameString).toEqual(" Andrew Edward Paul Chris John") end) it("shifts empty array", function() local empty = {} local none = shift(empty) - expect(empty).toEqual({}) - expect(none).to.equal(nil) + jestExpect(empty).toEqual({}) + jestExpect(none).toEqual(nil) end) if _G.__DEV__ then it("throws error on non-array", function() local nonarr = "abc" - expect(function() shift(nonarr) end).to.throw("Array.shift called on non-array string") + jestExpect(function() shift(nonarr) end).toThrow("Array.shift called on non-array string") end) end end \ No newline at end of file diff --git a/src/Array/__tests__/slice.spec.lua b/src/Array/__tests__/slice.spec.lua index ef532db..770e08b 100644 --- a/src/Array/__tests__/slice.spec.lua +++ b/src/Array/__tests__/slice.spec.lua @@ -1,53 +1,55 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` ---!nocheck - -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice return function() - local slice = require(script.Parent.Parent.slice) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local slice = require(Array.slice) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("Invalid argument", function() - expect(function() + jestExpect(function() slice(nil, 1) - end).to.throw() + end).toThrow() end) it("Return the whole array", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals) - expect(array_slice).toEqual({"ant", "bison", "camel", "duck", "elephant"}) + jestExpect(array_slice).toEqual({"ant", "bison", "camel", "duck", "elephant"}) end) it("Return from index 3 to end", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 3) - expect(array_slice).toEqual({"camel", "duck", "elephant"}) + jestExpect(array_slice).toEqual({"camel", "duck", "elephant"}) end) it("Return from index 3 to 5", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 3, 5) - expect(array_slice).toEqual({"camel", "duck"}) + jestExpect(array_slice).toEqual({"camel", "duck"}) end) it("Return from index 2 to index 6 (out of bounds)", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 2, 6) - expect(array_slice).toEqual({"bison", "camel", "duck", "elephant"}) + jestExpect(array_slice).toEqual({"bison", "camel", "duck", "elephant"}) end) describe("Negative indices", function() it("Return from index 0 to end", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 0) - expect(array_slice).toEqual({"elephant"}) + jestExpect(array_slice).toEqual({"elephant"}) end) it("Return from index -1 to 0", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, -1, 0) - expect(array_slice).toEqual({"duck"}) + jestExpect(array_slice).toEqual({"duck"}) end) end) @@ -55,13 +57,13 @@ return function() it("Start index out of bounds", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 10) - expect(array_slice).toEqual({}) + jestExpect(array_slice).toEqual({}) end) it("Start index after end index", function() local animals = {"ant", "bison", "camel", "duck", "elephant"} local array_slice = slice(animals, 2, 1) - expect(array_slice).toEqual({}) + jestExpect(array_slice).toEqual({}) end) end) end \ No newline at end of file diff --git a/src/Array/__tests__/some.spec.lua b/src/Array/__tests__/some.spec.lua index fc2390c..e40236f 100644 --- a/src/Array/__tests__/some.spec.lua +++ b/src/Array/__tests__/some.spec.lua @@ -1,27 +1,32 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` ---!nocheck - -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some return function() - local some = require(script.Parent.Parent.some) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local some = require(Array.some) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect it("Invalid argument", function() - expect(function() - some(nil, function() end) - end).to.throw() - expect(function() - some({0, 1}, nil) - end).to.throw() + -- roblox-cli analyze fails because map is called with an + -- invalid argument, so it needs to be cast to any + local someAny: any = some + jestExpect(function() + someAny(nil, function() end) + end).toThrow() + jestExpect(function() + someAny({0, 1}, nil) + end).toThrow() end) it("Testing value of array elements", function() local isBiggerthan10 = function(element, index, array) return element > 10 end - expect(some({2, 5, 8, 1, 4}, isBiggerthan10)).to.equal(false) - expect(some({12, 5, 8, 1, 4}, isBiggerthan10)).to.equal(true) + jestExpect(some({2, 5, 8, 1, 4}, isBiggerthan10)).toEqual(false) + jestExpect(some({12, 5, 8, 1, 4}, isBiggerthan10)).toEqual(true) end) it("Checking whether a value exists in an array", function() @@ -31,8 +36,8 @@ return function() return val == arrVal end) end - expect(checkAvailability(fruits, "kela")).to.equal(false) - expect(checkAvailability(fruits, "banana")).to.equal(true) + jestExpect(checkAvailability(fruits, "kela")).toEqual(false) + jestExpect(checkAvailability(fruits, "banana")).toEqual(true) end) it("Converting any value to Boolean", function() @@ -42,9 +47,9 @@ return function() return t == value end) end - expect(getBoolean(false)).to.equal(false) - expect(getBoolean("false")).to.equal(false) - expect(getBoolean(1)).to.equal(true) - expect(getBoolean("true")).to.equal(true) + jestExpect(getBoolean(false)).toEqual(false) + jestExpect(getBoolean("false")).toEqual(false) + jestExpect(getBoolean(1)).toEqual(true) + jestExpect(getBoolean("true")).toEqual(true) end) end \ No newline at end of file diff --git a/src/Array/__tests__/sort.spec.lua b/src/Array/__tests__/sort.spec.lua index a0c9ede..a1a90e6 100644 --- a/src/Array/__tests__/sort.spec.lua +++ b/src/Array/__tests__/sort.spec.lua @@ -3,53 +3,54 @@ return function() local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent local sort = require(Array.sort) + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + it("sorts string by default", function() - local expect: any = expect local months = { "March", "Jan", "Feb", "Dec" } sort(months) - expect(months).toEqual({ "Dec", "Feb", "Jan", "March" }) + jestExpect(months).toEqual({ "Dec", "Feb", "Jan", "March" }) end) it("returns the same array", function() local array = {} - expect(sort(array)).to.equal(array) + jestExpect(sort(array)).toBe(array) end) it("compares non-string values as strings", function() - local expect: any = expect local numbers = { 4, 5, 10, 88 } sort(numbers) - expect(numbers).toEqual({ 10, 4, 5, 88 }) + jestExpect(numbers).toEqual({ 10, 4, 5, 88 }) end) describe("with comparator", function() it("throws if comparator is not a function", function() - expect(function() + jestExpect(function() sort({}, "foo") - end).to.throw("invalid argument to Array.sort: compareFunction must be a function") + end).toThrow("invalid argument to Array.sort: compareFunction must be a function") end) it("throws when the compare function does not return a number", function() - expect(function() + jestExpect(function() sort({ 2, 1 }, function() return "foo" end) - end).to.throw("invalid result from compare function, expected number but got string") + end).toThrow("invalid result from compare function, expected number but got string") end) it("sorts a list of numbers", function() - local expect: any = expect local numbers = { 4, 2, 5, 1, 3 } sort(numbers, function(a, b) return a - b end) - expect(numbers).toEqual({ 1, 2, 3, 4, 5 }) + jestExpect(numbers).toEqual({ 1, 2, 3, 4, 5 }) end) it("sorts a list of objects", function() - local expect: any = expect -- deviation: table.sort is not stable, so -- equal items does not stay in the same order. local items = { @@ -64,7 +65,7 @@ return function() sort(items, function(a, b) return a.value - b.value end) - expect(items).toEqual({ + jestExpect(items).toEqual({ { name = 'The', value = -12 }, { name = 'Magnetic', value = 13 }, { name = 'Edward', value = 21 }, @@ -86,7 +87,7 @@ return function() return 0 end) - expect(items).toEqual({ + jestExpect(items).toEqual({ { name = 'And', value = 45 }, { name = 'Edward', value = 21 }, { name = 'Magnetic', value = 13 }, diff --git a/src/Array/__tests__/splice.spec.lua b/src/Array/__tests__/splice.spec.lua index 9143015..197155f 100644 --- a/src/Array/__tests__/splice.spec.lua +++ b/src/Array/__tests__/splice.spec.lua @@ -1,72 +1,75 @@ --- FIXME: roblox-cli has special, hard-coded types for TestEZ that break when we --- use custom matchers added via `expect.extend` ---!nocheck - -- Tests adapted directly from examples at: -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice return function() - local splice = require(script.Parent.Parent.splice) + local Array = script.Parent.Parent + local LuauPolyfill = Array.Parent + local splice = require(Array.splice) + + local Packages = LuauPolyfill.Parent + local JestRoblox = require(Packages.Dev.JestRoblox) + local jestExpect = JestRoblox.Globals.expect + it('Remove 0 (zero) elements before index 3, and insert "drum"', function() local myFish = {"angel", "clown", "mandarin", "sturgeon"} local removed = splice(myFish, 3, 0, "drum") - expect(myFish).toEqual({"angel", "clown", "drum", "mandarin", "sturgeon"}) - expect(removed).toEqual({}) + jestExpect(myFish).toEqual({"angel", "clown", "drum", "mandarin", "sturgeon"}) + jestExpect(removed).toEqual({}) end) it('Remove 0 (zero) elements before index 3, and insert "drum" and "guitar"', function() local myFish = {"angel", "clown", "mandarin", "sturgeon"} local removed = splice(myFish, 3, 0, "drum", "guitar") - expect(myFish).toEqual({"angel", "clown", "drum", "guitar", "mandarin", "sturgeon"}) - expect(removed).toEqual({}) + jestExpect(myFish).toEqual({"angel", "clown", "drum", "guitar", "mandarin", "sturgeon"}) + jestExpect(removed).toEqual({}) end) it('Remove 1 element at index 4', function() local myFish = {"angel", "clown", "drum", "mandarin", "sturgeon"} local removed = splice(myFish, 4, 1) - expect(myFish).toEqual({"angel", "clown", "drum", "sturgeon"}) - expect(removed).toEqual({"mandarin"}) + jestExpect(myFish).toEqual({"angel", "clown", "drum", "sturgeon"}) + jestExpect(removed).toEqual({"mandarin"}) end) it('Remove 1 element at index 3, and insert "trumpet"', function() local myFish = {"angel", "clown", "drum", "sturgeon"} local removed = splice(myFish, 3, 1, "trumpet") - expect(myFish).toEqual({"angel", "clown", "trumpet", "sturgeon"}) - expect(removed).toEqual({"drum"}) + jestExpect(myFish).toEqual({"angel", "clown", "trumpet", "sturgeon"}) + jestExpect(removed).toEqual({"drum"}) end) it('Remove 2 elements from index 1, and insert "parrot", "anemone" and "blue"', function() local myFish = {'angel', 'clown', 'trumpet', 'sturgeon'} local removed = splice(myFish, 1, 2, 'parrot', 'anemone', 'blue') - expect(myFish).toEqual({"parrot", "anemone", "blue", "trumpet", "sturgeon"} ) - expect(removed).toEqual({"angel", "clown"}) + jestExpect(myFish).toEqual({"parrot", "anemone", "blue", "trumpet", "sturgeon"} ) + jestExpect(removed).toEqual({"angel", "clown"}) end) it('Remove 2 elements from index 3', function() local myFish = {'parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'} local removed = splice(myFish, 3, 2) - expect(myFish).toEqual({"parrot", "anemone", "sturgeon"} ) - expect(removed).toEqual({"blue", "trumpet"}) + jestExpect(myFish).toEqual({"parrot", "anemone", "sturgeon"} ) + jestExpect(removed).toEqual({"blue", "trumpet"}) end) it('Remove 1 element from index -1', function() local myFish = {'angel', 'clown', 'mandarin', 'sturgeon'} local removed = splice(myFish, -1, 1) - expect(myFish).toEqual({"angel", "clown", "sturgeon"} ) - expect(removed).toEqual({"mandarin"}) + jestExpect(myFish).toEqual({"angel", "clown", "sturgeon"} ) + jestExpect(removed).toEqual({"mandarin"}) end) it('Remove all elements from index 3', function() local myFish = {'angel', 'clown', 'mandarin', 'sturgeon'} local removed = splice(myFish, 3) - expect(myFish).toEqual({"angel", "clown"}) - expect(removed).toEqual({"mandarin", "sturgeon"}) + jestExpect(myFish).toEqual({"angel", "clown"}) + jestExpect(removed).toEqual({"mandarin", "sturgeon"}) end) end \ No newline at end of file diff --git a/src/Array/reduce.lua b/src/Array/reduce.lua index 8663a2e..ad85300 100644 --- a/src/Array/reduce.lua +++ b/src/Array/reduce.lua @@ -5,7 +5,7 @@ type Function = (any, any, any, any) -> any; -- Implements Javascript's `Array.prototype.reduce` as defined below -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce -return function(t: Array, callback: Function, initialValue: any): any +return function(t: Array, callback: Function, initialValue: any?): any if typeof(t) ~= "table" then error(string.format("Array.reduce called on %s", typeof(t))) end diff --git a/src/Array/some.lua b/src/Array/some.lua index 633ef85..17e0509 100644 --- a/src/Array/some.lua +++ b/src/Array/some.lua @@ -5,7 +5,7 @@ type Function = (any, any?, any?, any?) -> any; -- Implements Javascript's `Array.prototype.map` as defined below -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some -return function(t: Array, fun: Function, thisArg: any) +return function(t: Array, fun: Function, thisArg: any?) if typeof(t) ~= "table" then error(string.format("Array.some called on %s", typeof(t))) end diff --git a/test-model.project.json b/test-model.project.json index 8c95998..5f8dbea 100644 --- a/test-model.project.json +++ b/test-model.project.json @@ -3,10 +3,10 @@ "tree": { "$className": "Folder", "Packages": { - "$path": "Packages" - }, - "LuauPolyfill": { - "$path": "src" + "$path": "Packages", + "LuauPolyfill": { + "$path": "src" + } } } } \ No newline at end of file