-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbridge.spec.luau
More file actions
61 lines (54 loc) · 1.82 KB
/
bridge.spec.luau
File metadata and controls
61 lines (54 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- ROBLOX upstream: https://github.com/facebook/react/blob/v17.0.1/packages/react-devtools-shared/src/__tests__/bridge-test.js
--[[*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
]]
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local describe = JestGlobals.describe
local it = JestGlobals.it
local beforeEach = JestGlobals.beforeEach
local jestExpect = JestGlobals.expect
local jest = JestGlobals.jest
describe("bridge", function()
local Bridge
beforeEach(function()
jest.resetModules()
jest.useFakeTimers()
Bridge = require("../bridge")
end)
it("should shutdown properly", function()
local wall = {
listen = jest.fn(function()
return function() end
end),
send = jest.fn(),
}
local bridge = Bridge.new(wall)
-- Check that we're wired up correctly.
bridge:send("reloadAppForProfiling")
jest.runAllTimers()
jestExpect(wall.send).toHaveBeenCalledWith("reloadAppForProfiling")
-- Should flush pending messages and then shut down.
wall.send.mockClear()
bridge:send("update", "1")
bridge:send("update", "2")
bridge:shutdown()
jest.runAllTimers()
jestExpect(wall.send).toHaveBeenCalledWith("update", "1")
jestExpect(wall.send).toHaveBeenCalledWith("update", "2")
jestExpect(wall.send).toHaveBeenCalledWith("shutdown")
-- Verify that the Bridge doesn't send messages after shutdown.
wall.send.mockClear()
-- ROBLOX deviation: instead of spying on console, use toWarnDev matcher
jestExpect(function()
bridge:send("should not send")
end).toWarnDev(
'Cannot send message "should not send" through a Bridge that has been shutdown.',
{ withoutStack = true }
)
jest.runAllTimers()
jestExpect(wall.send).never.toHaveBeenCalled()
end)
end)