X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/193354f3e791fea340e58d01aacee8afcc195116..f13584987de14ea9d3080df6ce46f6dec21b8393:/services/workbench2/src/components/search-input/search-input.test.tsx

diff --git a/services/workbench2/src/components/search-input/search-input.test.tsx b/services/workbench2/src/components/search-input/search-input.test.tsx
index ba70f752b9..ba0f43d8b5 100644
--- a/services/workbench2/src/components/search-input/search-input.test.tsx
+++ b/services/workbench2/src/components/search-input/search-input.test.tsx
@@ -11,11 +11,10 @@ configure({ adapter: new Adapter() });
 
 describe("<SearchInput />", () => {
 
-    jest.useFakeTimers();
-
     let onSearch: () => void;
 
     beforeEach(() => {
+        jest.useFakeTimers();
         onSearch = jest.fn();
     });
 
@@ -45,7 +44,7 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000} />);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
             searchInput.find("form").simulate("submit");
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
             expect(onSearch).toBeCalledWith("current value");
         });
@@ -57,37 +56,37 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} />);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
             expect(onSearch).not.toBeCalled();
-            jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
+            jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         it("calls onSearch after the time specified in props has passed", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={2000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).not.toBeCalled();
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         it("calls onSearch only once after no change happened during the specified time", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(500);
+            jest.advanceTimersByTime(500);
             searchInput.find("input").simulate("change", { target: { value: "changed value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
         });
 
         it("calls onSearch again after the specified time has passed since previous call", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(500);
+            jest.advanceTimersByTime(500);
             searchInput.find("input").simulate("change", { target: { value: "intermediate value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("intermediate value");
             searchInput.find("input").simulate("change", { target: { value: "latest value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("latest value");
             expect(onSearch).toHaveBeenCalledTimes(2);
 
@@ -100,18 +99,18 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="abc" value="123" onSearch={onSearch} debounce={1000}/>);
 
             // component should clear value upon creation
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("");
             expect(onSearch).toHaveBeenCalledTimes(1);
 
             // component should not clear on same selfClearProp
             searchInput.setProps({ selfClearProp: 'abc' });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
 
             // component should clear on selfClearProp change
             searchInput.setProps({ selfClearProp: '111' });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("");
             expect(onSearch).toHaveBeenCalledTimes(2);
         });
