diff --git a/src/index.d.ts b/src/index.d.ts
index d0f8c86bfa8..062fd6e01fe 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -1,3 +1,2 @@
///
///
-///
diff --git a/src/test/find_test_subject.js b/src/test/find_test_subject.ts
similarity index 64%
rename from src/test/find_test_subject.js
rename to src/test/find_test_subject.ts
index 15d2bf6c342..9c590eeedbb 100644
--- a/src/test/find_test_subject.js
+++ b/src/test/find_test_subject.ts
@@ -1,3 +1,10 @@
+import { ReactWrapper, ShallowWrapper } from 'enzyme';
+
+type FindTestSubject = (
+ mountedComponent: T,
+ testSubjectSelector: string
+) => ReturnType;
+
/**
* Find node which matches a specific test subject selector. Returns ReactWrappers around DOM element,
* https://github.com/airbnb/enzyme/tree/master/docs/api/ReactWrapper.
@@ -17,12 +24,22 @@ const MATCHERS = [
'*=', // Contains substring
];
-export const findTestSubject = (mountedComponent, testSubjectSelector, matcher = '~=') => {
+export const findTestSubject: FindTestSubject = (
+ mountedComponent,
+ testSubjectSelector,
+ matcher = '~='
+) => {
if (!MATCHERS.includes(matcher)) {
- throw new Error(`Matcher ${matcher} not found in list of allowed matchers: ${MATCHERS.join(' ')}`);
+ throw new Error(
+ `Matcher ${matcher} not found in list of allowed matchers: ${MATCHERS.join(
+ ' '
+ )}`
+ );
}
- const testSubject = mountedComponent.find(`[data-test-subj${matcher}"${testSubjectSelector}"]`);
+ const testSubject = mountedComponent.find(
+ `[data-test-subj${matcher}"${testSubjectSelector}"]`
+ );
// Restores Enzyme 2's find behavior, which was to only return ReactWrappers around DOM elements.
// Enzyme 3 returns ReactWrappers around both DOM elements and React components.
diff --git a/src/test/index.d.ts b/src/test/index.d.ts
deleted file mode 100644
index e75d40657aa..00000000000
--- a/src/test/index.d.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { ShallowWrapper, ReactWrapper } from 'enzyme';
-
-declare module '@elastic/eui' {
- export function findTestSubject (
- mountedComponent: T,
- testSubjectSelector: string
- ): ReturnType;
-}
diff --git a/src/test/index.js b/src/test/index.ts
similarity index 63%
rename from src/test/index.js
rename to src/test/index.ts
index af1224e7b7b..08a7fc9ccd1 100644
--- a/src/test/index.js
+++ b/src/test/index.ts
@@ -1,4 +1,7 @@
export { requiredProps } from './required_props';
export { takeMountedSnapshot } from './take_mounted_snapshot';
export { findTestSubject } from './find_test_subject';
-export { startThrowingReactWarnings, stopThrowingReactWarnings } from './react_warnings';
+export {
+ startThrowingReactWarnings,
+ stopThrowingReactWarnings,
+} from './react_warnings';
diff --git a/src/test/patch_random.js b/src/test/patch_random.js
deleted file mode 100644
index de18b8023de..00000000000
--- a/src/test/patch_random.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const _mathRandom = Math.random;
-
-export function patchRandom() {
- let x = 0;
- Math.random = () => x += 0.00001;
-}
-
-export function unpatchRandom() {
- Math.random = _mathRandom;
-}
diff --git a/src/test/patch_random.ts b/src/test/patch_random.ts
new file mode 100644
index 00000000000..65ef2b6c4cd
--- /dev/null
+++ b/src/test/patch_random.ts
@@ -0,0 +1,10 @@
+const originalMathRandom = Math.random;
+
+export function patchRandom() {
+ let x = 0;
+ Math.random = () => (x += 0.00001);
+}
+
+export function unpatchRandom() {
+ Math.random = originalMathRandom;
+}
diff --git a/src/test/react_warnings.js b/src/test/react_warnings.ts
similarity index 53%
rename from src/test/react_warnings.js
rename to src/test/react_warnings.ts
index 9917990b4db..8105da46b2e 100644
--- a/src/test/react_warnings.js
+++ b/src/test/react_warnings.ts
@@ -1,3 +1,5 @@
+/* tslint:disable:no-console */
+
/*
Use this utility to throw errors whenever React complains via the console
about things like invalid propTypes. This lets us assert that a propType
@@ -9,14 +11,16 @@
afterAll(stopThrowingReactWarnings);
*/
-const consoleWarn = console.warn; // eslint-disable-line no-console
-const consoleError = console.error; // eslint-disable-line no-console
+const consoleWarn = console.warn;
+const consoleError = console.error;
export const startThrowingReactWarnings = () => {
- console.warn = console.error = (msg) => { throw msg; }; // eslint-disable-line no-console
+ console.warn = console.error = (msg: any) => {
+ throw msg;
+ };
};
export const stopThrowingReactWarnings = () => {
- console.warn = consoleWarn; // eslint-disable-line no-console
- console.error = consoleError; // eslint-disable-line no-console
+ console.warn = consoleWarn;
+ console.error = consoleError;
};
diff --git a/src/test/take_mounted_snapshot.js b/src/test/take_mounted_snapshot.ts
similarity index 74%
rename from src/test/take_mounted_snapshot.js
rename to src/test/take_mounted_snapshot.ts
index cce0fbc8740..69f4ab57b7a 100644
--- a/src/test/take_mounted_snapshot.js
+++ b/src/test/take_mounted_snapshot.ts
@@ -1,10 +1,15 @@
+import { ReactWrapper } from 'enzyme';
+import { Component } from 'react';
+
/**
* Use this function to generate a Jest snapshot of components that have been fully rendered
* using Enzyme's `mount` method. Typically, a mounted component will result in a snapshot
* containing both React components and HTML elements. This function removes the React components,
* leaving only HTML elements in the snapshot.
*/
-export const takeMountedSnapshot = mountedComponent => {
+export const takeMountedSnapshot = (
+ mountedComponent: ReactWrapper<{}, {}, Component>
+) => {
const html = mountedComponent.html();
const template = document.createElement('template');
template.innerHTML = html;
diff --git a/src/test/time_execution.js b/src/test/time_execution.ts
similarity index 64%
rename from src/test/time_execution.js
rename to src/test/time_execution.ts
index 582e03d3997..dd3f6ee6414 100644
--- a/src/test/time_execution.js
+++ b/src/test/time_execution.ts
@@ -1,12 +1,16 @@
-export function timeExecution(fn) {
+export function timeExecution(fn: () => void) {
const start = process.hrtime();
fn();
const [seconds, nanoseconds] = process.hrtime(start);
- const milliseconds = (seconds * 1000) + (nanoseconds / 1000000);
+ const milliseconds = seconds * 1000 + nanoseconds / 1000000;
return milliseconds;
}
-export function benchmarkFunction(fn, warmupRuns = 3, benchmarkRuns = 3) {
+export function benchmarkFunction(
+ fn: () => void,
+ warmupRuns = 3,
+ benchmarkRuns = 3
+) {
// warmup v8 optimizations, cache, etc
for (let i = 0; i < warmupRuns; i++) {
fn();