UNPKG

@testing-library/react-native

Version:

Simple and complete React Native testing utilities that encourage good testing practices.

71 lines (64 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setup = setup; var _timers = require("../../helpers/timers"); var _press = require("../press"); var _type = require("../type"); var _clear = require("../clear"); /** * This functions allow wait to work correctly under both real and fake Jest timers. */ function universalJestAdvanceTimersBy(ms) { if ((0, _timers.jestFakeTimersAreEnabled)()) { return jest.advanceTimersByTime(ms); } else { return Promise.resolve(); } } const defaultOptions = { delay: 0, advanceTimers: universalJestAdvanceTimersBy }; /** * Creates a new instance of user event instance with the given options. * * @param options * @returns UserEvent instance */ function setup(options) { const config = createConfig(options); const instance = createInstance(config); return instance; } /** * Options affecting all user event interactions. * * @param delay between some subsequent inputs like typing a series of characters * @param advanceTimers function to be called to advance fake timers */ function createConfig(options) { return { ...defaultOptions, ...options }; } /** * UserEvent instance used to invoke user interaction functions. */ function createInstance(config) { const instance = { config }; // We need to bind these functions, as they access the config through 'this.config'. const api = { press: _press.press.bind(instance), longPress: _press.longPress.bind(instance), type: _type.type.bind(instance), clear: _clear.clear.bind(instance) }; Object.assign(instance, api); return instance; } //# sourceMappingURL=setup.js.map