From cb4c4b053b3d93733ca3e115b529dfc8a95770b1 Mon Sep 17 00:00:00 2001 From: Denis Strelkov Date: Mon, 8 Jun 2020 23:09:58 +0300 Subject: [PATCH] Change type of cleanup fun, fix local test run --- src/ReactTestingLibrary.re | 2 +- src/ReactTestingLibrary.rei | 2 +- src/__tests__/ReactTestingLibrary_test.re | 35 ++++++++++++++----- .../ReactTestingLibrary_test.bs.js.snap | 2 ++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/ReactTestingLibrary.re b/src/ReactTestingLibrary.re index 54160db..f51a45d 100644 --- a/src/ReactTestingLibrary.re +++ b/src/ReactTestingLibrary.re @@ -16,7 +16,7 @@ type renderOptions = { }; [@bs.module "@testing-library/react"] -external cleanup: unit => unit = "cleanup"; +external cleanup: unit => Js.Promise.t(unit) = "cleanup"; [@bs.module "@testing-library/react"] external _act: (unit => Js.undefined(Js.Promise.t('a))) => unit = "act"; diff --git a/src/ReactTestingLibrary.rei b/src/ReactTestingLibrary.rei index 308671d..49c3ee4 100644 --- a/src/ReactTestingLibrary.rei +++ b/src/ReactTestingLibrary.rei @@ -84,7 +84,7 @@ type renderOptions = { }; [@bs.module "@testing-library/react"] -external cleanup: unit => unit = "cleanup"; +external cleanup: unit => Js.Promise.t(unit) = "cleanup"; let act: (unit => unit) => unit; diff --git a/src/__tests__/ReactTestingLibrary_test.re b/src/__tests__/ReactTestingLibrary_test.re index e3bfd75..15869dc 100644 --- a/src/__tests__/ReactTestingLibrary_test.re +++ b/src/__tests__/ReactTestingLibrary_test.re @@ -16,14 +16,15 @@ module Counter = { [@react.component] let make = () => { - let (state, dispatch) = React.useReducer( - (state, action) => - switch (action) { - | Inc => state + 1 - | Dec => state - 1 - }, - 0 - ); + let (state, dispatch) = + React.useReducer( + (state, action) => + switch (action) { + | Inc => state + 1 + | Dec => state - 1 + }, + 0, + );
{ReasonReact.string("Count: " ++ string_of_int(state))} @@ -33,7 +34,7 @@ module Counter = { -
+ ; }; }; @@ -685,4 +686,20 @@ describe("ReactTestingLibrary", () => { |> expect |> toMatchSnapshot; }); + + testPromise("Cleaunp, (element not found)", () => { + let result = element |> render; + + cleanup() + |> Js.Promise.( + then_(_ => { + Js.Promise.resolve( + result + |> queryByTestId(~matcher=`Str("h1-heading")) + |> expect + |> toMatchSnapshot, + ) + }) + ); + }); }); diff --git a/src/__tests__/__snapshots__/ReactTestingLibrary_test.bs.js.snap b/src/__tests__/__snapshots__/ReactTestingLibrary_test.bs.js.snap index 3d252be..197356f 100644 --- a/src/__tests__/__snapshots__/ReactTestingLibrary_test.bs.js.snap +++ b/src/__tests__/__snapshots__/ReactTestingLibrary_test.bs.js.snap @@ -400,6 +400,8 @@ exports[`ReactTestingLibrary ByTitle queryByTitle works 1`] = ` /> `; +exports[`ReactTestingLibrary Cleaunp, (element not found) 1`] = `null`; + exports[`ReactTestingLibrary act works 1`] = `
Count: 1