Internally in @joystick.js/ui and @joystick.js/node, for tests, function calls are automatically tracked to all core APIs. This allows you to test the behavior of your app in a nearly-transparent way, confirming that what you intended to call was called without the need for excessive mocking or heavy instrumentation at the app level.
Accessing Calls
To access calls to any of the listed "Tracked Calls" below, the test.utils.get_function_calls() method can be utilized:
const calls = await test.utils.get_function_calls('<tracked_call_path>');
Check If Function Called
To check if a specific function has received any calls (with a boolean response), the test.utils.function_called() method can be utilized:
const function_called = await test.utils.function_called('<tracked_call_path>');
Tracked Calls
The following calls are tracked across @joystick.js/ui and @joystick.js/node. Below, the path of the tracked calls that you would pass to the test.utils.get_function_calls() or test.utils.function_called() methods described above are listed.
@joystick.js/ui
In components, function calls can be tracked on a per-component basis by utilizing the test.name value in your component options. If this is not available, Joystick will create a random ID to group together function calls for a component.
Lifecycle Function Calls
ui.<test.name || random_id>.render_for_mountui.<test.name || random_id>.rerenderui.<test.name || random_id>.lifecycle.on_before_mountui.<test.name || random_id>.lifecycle.on_mountui.<test.name || random_id>.lifecycle.on_before_renderui.<test.name || random_id>.lifecycle.on_renderui.<test.name || random_id>.lifecycle.on_update_propsui.<test.name || random_id>.lifecycle.on_refetch_dataui.<test.name || random_id>.lifecycle.on_before_unmount
Data
ui.<test.name || random_id>.data.refetch
Events
ui.<test.name || random_id>.events.<event_type>.selector_<selector>
Methods
ui.<test.name || random_id>.methods.<method_name>
Uploads
ui.upload.<uploader_name>
Websockets
ui.<test.name || random_id>.websockets.sendui.<test.name || random_id>.websockets.on_openui.<test.name || random_id>.websockets.on_messageui.<test.name || random_id>.websockets.on_close
Instance Methods
ui.<test.name || random_id>.set_intervalui.<test.name || random_id>.set_timeoutui.<test.name || random_id>.set_state
@joystick.js/node
On the server, function calls are tracked globally (as there is only one server instance to track calls for).
Actions
node.actions.<action_name>.abortnode.actions.<action_name>.runnode.actions.<action_name>.steps.<step_name>node.actions.<action_name>.steps.<step_name>.on_successnode.actions.<action_name>.steps.<step_name>.on_error
API
node.api.getters.<getter_name>node.api.getters.<getter_name>.authorizednode.api.setters.<setter_name>node.api.setters.<setter_name>.authorized
node.email.send
Queues
node.queues.<queue_name>.jobs.<job_name>
Uploaders
node.uploaders.<uploader_name>.on_before_uploadnode.uploaders.<uploader_name>.on_after_uploadnode.uploaders.<uploader_name>.file_namenode.uploaders.<uploader_name>.max_size_in_megabytes
Websockets
node.websockets.<server_name>.sendnode.websockets.<server_name>.on_opennode.websockets.<server_name>.on_messagenode.websockets.<server_name>.on_close
API
test.utils.function_called()
test.utils.function_called(tracked_call_path: string) => Promise -> boolean;
Parameters
- tracked_call_path string required
- Either a pre-defined Joystick call path, or a custom call path used in your app.
test.utils.get_function_calls()
test.utils.get_function_calls(tracked_call_path: string) => Promise -> array[object];
Parameters
- tracked_call_path string required
- Either a pre-defined Joystick call path, or a custom call path used in your app.