-
Notifications
You must be signed in to change notification settings - Fork 327
LLD:Mocking
In order to be able to complete all OK/KO cases of all flows for testing and development, we expose a way to mock events that require interaction with a real device. When running with the env variable MOCK
you'll have access to mockDeviceEvent
which receives one or more events that will be emitted to the subscribed observers triggering the associated actions.
Simply open the console, mockDeviceEvent
is available as a global window variable. Pass the snippet below or any event of your liking to that method.
As it's done in the onboarding.spec.js
file, we need to get access to that method via a call to const mockeDeviceEvent = getMockDeviceEvent(app)
afterward the functionality of the method is the same as for dev with the exception of having to await
the result to not break the tests.
It allows us to interact with all parts of the application without the need for a real device or real accounts.
These are a series of snippets that allow you to reach the OK and KO ends of a device interaction for each of the flows. For the KOs, we can essentially use the name of any error and it will throw it, depending on the flow ones make more sense than others.
mockDeviceEvent({ type: "opened" })
mockDeviceEvent({ type: "device-permission-requested", wording: "Allow manager" })
mockDeviceEvent({ type: "device-permission-granted" })
(note it's not an array) We could make other profiles for devices available and fix the sizes of the apps returned by mockListAppsResult
to test things like the storage breakdown in the manager. Note for devs in the console you will be able to run this snippet only because we've exposed the dependencies as globals when in mock.
Refer to the signature of mockListAppsResult
to see the doors it opens. But a tldr is the first parameter are the apps available in the catalog, the second is the list of installed apps.
mockDeviceEvent(
{ type: "listingApps", deviceInfo: deviceInfo155 },
{
type: "result",
result: mockListAppsResult("Bitcoin", "Bitcoin", deviceInfo155),
}
)
mockDeviceEvent({ type: "error", error: { name: "DisconnectedDevice" } })
mockDeviceEvent({ type: "error", error: { name: "GenuineCheckFailed" } })
mockDeviceEvent({ type: "error", error: { name: "WrongDeviceForAccount" } })
mockDeviceEvent({ type: "error", error: { name: "UserRefusedOnDevice" } })
- Ledger Live Desktop
- Ledger Live Mobile
-
Ledger Live Common
- Introduction
- Currency Models
- Currency Bridge
- Account
- Account Bridge
- apps
- appsCheckAllAppVersions
- ledger-live bot
- Canonical Ways to Investigate Bugs
- Coin Integration Introduction
- Countervalues
- Packages Duplicates
- Derivation
- Developing with CLI
- Developing
- Gist Firmware Update
- Gist Transaction
- Hardware Wallet Logic
- Socket
- Assorted tips
- Integration Tests
- Process
- Monorepository Migration Guide
- Issues, Workaround and Tricks
- Common CI Troubleshooting
- Create staging builds using the CI
- Deprecated