├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CREDITS.md ├── bsconfig.json ├── changelog.md ├── license ├── package.json ├── readme.md ├── setupTests.js ├── src ├── ReactTestingLibrary.res ├── ReactTestingLibrary.resi └── __tests__ │ ├── ReactTestingLibrary_test.res │ └── __snapshots__ │ └── ReactTestingLibrary_test.bs.js.snap └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | *.re linguist-language=Reason 4 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | node-version: ['12', '10'] 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Setup Node ${{ matrix.node-version }} 14 | uses: actions/setup-node@v1 15 | with: 16 | node-version: ${{ matrix.node-version }} 17 | - name: Setup Deno 0.40 18 | uses: denolib/setup-deno@v2 19 | with: 20 | deno-version: '0.40' 21 | - run: yarn install --frozen-lockfile 22 | - run: yarn --check-files 23 | - run: yarn test 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | node_modules 3 | 4 | # Build 5 | _coverage 6 | src/**/*.bs.js 7 | lib 8 | .bsb.lock 9 | .merlin 10 | *.coverage 11 | 12 | # Logs 13 | *.log 14 | 15 | # macOS 16 | .*DS_Store 17 | -------------------------------------------------------------------------------- /CREDITS.md: -------------------------------------------------------------------------------- 1 | ## Credits 2 | 3 | Thanks to [@wyze](https://github.com/wyze/bs-react-testing-library) for these bindings, originally written in ReasonML + BuckleScript. 4 | -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bs-react-testing-library", 3 | "bsc-flags": ["-bs-no-version-header", "-bs-super-errors"], 4 | "warnings": { 5 | "number": "+A-48-42", 6 | "error": "+A-3-44-102" 7 | }, 8 | "reason": { 9 | "react-jsx": 3 10 | }, 11 | "refmt": 3, 12 | "package-specs": { 13 | "module": "commonjs", 14 | "in-source": true 15 | }, 16 | "suffix": ".bs.js", 17 | "bs-dependencies": ["bs-dom-testing-library", "@rescript/react"], 18 | "bs-dev-dependencies": ["@glennsl/bs-jest"], 19 | "sources": [ 20 | { 21 | "dir": "src", 22 | "subdirs": [ 23 | { 24 | "dir": "__tests__", 25 | "type": "dev" 26 | } 27 | ] 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | ## Change Log 2 | 3 | ### [v1.0.0](https://github.com/rescriptbr/react-testing-library/releases/tag/v1.0.0) (2021-04-21) 4 | 5 | * Migrating from reason syntax to rescript and reason-react to @rescript/react ([@vmarcosp](https://github.com/vmarcosp) in [f77a430](https://github.com/rescriptbr/react-testing-library/commit/f77a430)) 6 | 7 | 8 | ### [v1.0.0](https://github.com/rescriptbr/react-testing-library/releases/tag/v1.0.0) (2021-04-21) 9 | * Migrating from `reason-react` to `@rescript/react` 10 | 11 | ### [v0.8.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.8.0) (2020-10-21) 12 | 13 | * Upgrade to latest dependencies ([@wyze](https://github.com/wyze) in [#27](https://github.com/wyze/bs-react-testing-library/pull/27)) 14 | * Add sponsor button ([@wyze](https://github.com/wyze) in [c69f028](https://github.com/wyze/bs-react-testing-library/commit/c69f028)) 15 | 16 | ### [v0.7.3](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.7.3) (2020-06-18) 17 | 18 | * Fix test command ([@wyze](https://github.com/wyze) in [f9c5987](https://github.com/wyze/bs-react-testing-library/commit/f9c5987)) 19 | * Bump version for bs-dom-testing-library ([@johnridesabike](https://github.com/johnridesabike) in [#24](https://github.com/wyze/bs-react-testing-library/pull/24)) 20 | * Change type of cleanup function ([@denis-ok](https://github.com/denis-ok) in [#23](https://github.com/wyze/bs-react-testing-library/pull/23)) 21 | * Use denopkg.com ([@wyze](https://github.com/wyze) in [#22](https://github.com/wyze/bs-react-testing-library/pull/22)) 22 | * Update CI to try and work better ([@wyze](https://github.com/wyze) in [#21](https://github.com/wyze/bs-react-testing-library/pull/21)) 23 | 24 | ### [v0.7.2](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.7.2) (2020-04-13) 25 | 26 | * Fix bsconfig.json to allow `test` command to run ([@wyze](https://github.com/wyze) in [48b5343](https://github.com/wyze/bs-react-testing-library/commit/48b5343)) 27 | * Run bisect conditionally ([@wyze](https://github.com/wyze) in [#20](https://github.com/wyze/bs-react-testing-library/pull/20)) 28 | 29 | ### [v0.7.1](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.7.1) (2020-04-12) 30 | 31 | * Add support for `act` helper function ([@jihchi](https://github.com/jihchi) in [#17](https://github.com/wyze/bs-react-testing-library/pull/17)) 32 | * Switch to GitHub actions ([@wyze](https://github.com/wyze) in [#18](https://github.com/wyze/bs-react-testing-library/pull/18)) 33 | 34 | ### [v0.7.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.7.0) (2020-04-10) 35 | 36 | * Fix linguist to map files to Reason ([@wyze](https://github.com/wyze) in [ef9fb26](https://github.com/wyze/bs-react-testing-library/commit/ef9fb26)) 37 | * Upgrade devDependencies to latest versions ([@wyze](https://github.com/wyze) in [b4705a9](https://github.com/wyze/bs-react-testing-library/commit/b4705a9)) 38 | * Upgrade underlaying library ([@jihchi](https://github.com/jihchi) in [#13](https://github.com/wyze/bs-react-testing-library/pull/13)) 39 | * Remove warnings for implicit external names ([@justinba1010](https://github.com/justinba1010) in [#9](https://github.com/wyze/bs-react-testing-library/pull/9)) 40 | 41 | ### [v0.6.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.6.0) (2019-07-21) 42 | 43 | * Upgrade `extend` to fix CVE-2018-16492 ([@wyze](https://github.com/wyze) in [535d526](https://github.com/wyze/bs-react-testing-library/commit/535d526)) 44 | * Upgrade dependencies ([@wyze](https://github.com/wyze) in [5a73fe3](https://github.com/wyze/bs-react-testing-library/commit/5a73fe3)) 45 | * Upgrade react-testing-library to v8 ([@jihchi](https://github.com/jihchi) in [#5](https://github.com/wyze/bs-react-testing-library/pull/5)) 46 | 47 | ### [v0.5.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.5.0) (2019-04-24) 48 | 49 | * Meta file updates ([@wyze](https://github.com/wyze) in [9e91c93](https://github.com/wyze/bs-react-testing-library/commit/9e91c93)) 50 | * Fix `FireEvent` module ([@wyze](https://github.com/wyze) in [2e709fd](https://github.com/wyze/bs-react-testing-library/commit/2e709fd)) 51 | * Upgrade dependencies ([@wyze](https://github.com/wyze) in [cd924da](https://github.com/wyze/bs-react-testing-library/commit/cd924da)) 52 | * Improve readme example ([@benadamstyles](https://github.com/benadamstyles) in [#2](https://github.com/wyze/bs-react-testing-library/pull/2)) 53 | 54 | ### [v0.4.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.4.0) (2018-10-11) 55 | 56 | * [[`0ce29af4d8`](https://github.com/wyze/bs-react-testing-library/commit/0ce29af4d8)] - Remove non-functioning Simulate module (Neil Kistner) 57 | * [[`7b2350237a`](https://github.com/wyze/bs-react-testing-library/commit/7b2350237a)] - Upgrade dependencies and expose FireEvent from `bs-dom-testing-library` (Neil Kistner) 58 | 59 | ### [v0.3.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.3.0) (2018-09-20) 60 | 61 | * [[`a92da35f6f`](https://github.com/wyze/bs-react-testing-library/commit/a92da35f6f)] - Meta file updates (Neil Kistner) 62 | * [[`78128d354b`](https://github.com/wyze/bs-react-testing-library/commit/78128d354b)] - Update API with new queries from bs-dom-testing-library (Neil Kistner) 63 | * [[`bb5082301a`](https://github.com/wyze/bs-react-testing-library/commit/bb5082301a)] - Upgrade dependencies (Neil Kistner) 64 | 65 | ### [v0.2.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.2.0) (2018-07-29) 66 | 67 | * [[`e515c3437d`](https://github.com/wyze/bs-react-testing-library/commit/e515c3437d)] - Upgrade dependencies and code to go with it (Neil Kistner) 68 | * [[`7efd67d19e`](https://github.com/wyze/bs-react-testing-library/commit/7efd67d19e)] - Remove unused code in test (Neil Kistner) 69 | * [[`6a4ac2804f`](https://github.com/wyze/bs-react-testing-library/commit/6a4ac2804f)] - Update readme with proper usage (Neil Kistner) 70 | 71 | ### [v0.1.0](https://github.com/wyze/bs-react-testing-library/releases/tag/v0.1.0) (2018-06-05) 72 | 73 | * [[`7dd8119705`](https://github.com/wyze/bs-react-testing-library/commit/7dd8119705)] - Initial commit (Neil Kistner) 74 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Neil Kistner (neilkistner.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rescriptbr/testing-library", 3 | "version": "1.0.0", 4 | "description": "ReScript bindings for react-testing-library", 5 | "repository": "rescriptbr/react-testing-library", 6 | "author": { 7 | "name": "ReScript Brasil", 8 | "email": "vmarcosp.pereira@gmail.com" 9 | }, 10 | "license": "MIT", 11 | "files": [ 12 | "src/*.res", 13 | "src/*.resi", 14 | "bsconfig.json" 15 | ], 16 | "scripts": { 17 | "build": "bsb -make-world", 18 | "clean": "run-p clean:*", 19 | "clean:bsb": "bsb -clean-world", 20 | "jest": "jest --setupTestFrameworkScriptFile=./setupTests.js", 21 | "pretest": "yarn build", 22 | "test": "yarn jest" 23 | }, 24 | "keywords": [ 25 | "bucklescript", 26 | "react", 27 | "testing", 28 | "rescript-react", 29 | "rescript-react-testing-library" 30 | ], 31 | "dependencies": { 32 | "@testing-library/react": "^11.1.0", 33 | "bs-dom-testing-library": "^0.7.0" 34 | }, 35 | "peerDependencies": { 36 | "@rescript/react": "<0.10.1" 37 | }, 38 | "devDependencies": { 39 | "@glennsl/bs-jest": "^0.5.1", 40 | "@sheerun/mutationobserver-shim": "^0.3.3", 41 | "bs-platform": "^8.4.2", 42 | "npm-run-all": "^4.1.5", 43 | "react": "^17.0.0", 44 | "react-dom": "^17.0.0", 45 | "@rescript/react": "^0.10.2" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # @rescriptbr/react-testing-library 2 | 3 | > [ReScript](https://rescript-lang.org) bindings for [react-testing-library](https://github.com/testing-library/react-testing-library). 4 | 5 | ## Documentation 6 | 7 | The documentation is WIP, see [`src/__tests__`](src/__tests__) for some examples. 8 | 9 | ## Installation 10 | 11 | ```sh 12 | $ yarn add --dev @rescriptbr/react-testing-library 13 | 14 | # or.. 15 | 16 | $ npm install --save-dev @rescriptbr/react-testing-library 17 | ``` 18 | 19 | ## Usage 20 | 21 | #### Add to `bsconfig.json` 22 | 23 | ```json 24 | { 25 | "bs-dev-dependencies": [ 26 | "@rescriptbr/react-testing-library" 27 | ] 28 | } 29 | ``` 30 | 31 | #### With [`bs-jest`](//github.com/glennsl/bs-jest) 32 | 33 | ```ocaml 34 | open Jest 35 | open Expect 36 | open ReactTestingLibrary 37 | 38 | test("Component renders", () => 39 |
40 |

{React.string("Heading")}

41 |
42 | |> render 43 | |> container 44 | |> expect 45 | |> toMatchSnapshot 46 | ) 47 | ``` 48 | 49 | ## Examples 50 | 51 | See [`src/__tests__`](src/__tests__) for some examples. 52 | 53 | ## Development 54 | 55 | ```sh 56 | $ git clone https://github.com/wyze/bs-react-testing-library.git 57 | $ cd bs-react-testing-library 58 | $ yarn # or `npm install` 59 | ``` 60 | 61 | ## Build 62 | 63 | ```sh 64 | $ yarn build 65 | ``` 66 | 67 | ## Test 68 | 69 | ```sh 70 | $ yarn test 71 | ``` 72 | 73 | ## Change Log 74 | 75 | > [Full Change Log](changelog.md) 76 | 77 | ### [v1.0.0](https://github.com/rescriptbr/react-testing-library/releases/tag/v1.0.0) (2021-04-21) 78 | 79 | * Migrating from reason syntax to rescript and reason-react to @rescript/react ([@vmarcosp](https://github.com/vmarcosp) in [f77a430](https://github.com/rescriptbr/react-testing-library/commit/f77a430)) 80 | 81 | ## Credits 82 | 83 | See [CREDITS.md](CREDITS.md) 84 | 85 | ## License 86 | 87 | MIT © 88 | 89 | -------------------------------------------------------------------------------- /setupTests.js: -------------------------------------------------------------------------------- 1 | const MutationObserver = require('@sheerun/mutationobserver-shim'); 2 | 3 | window.MutationObserver = MutationObserver; 4 | -------------------------------------------------------------------------------- /src/ReactTestingLibrary.res: -------------------------------------------------------------------------------- 1 | open DomTestingLibrary 2 | 3 | module FireEvent = { 4 | include FireEvent 5 | } 6 | 7 | type renderResult 8 | type queries 9 | type renderOptions = { 10 | "container": Js.undefined, 11 | "baseElement": Js.undefined, 12 | "hydrate": Js.undefined, 13 | "wrapper": Js.undefined, 14 | "queries": Js.undefined, 15 | } 16 | 17 | @module("@testing-library/react") 18 | external cleanup: unit => unit = "cleanup" 19 | 20 | @module("@testing-library/react") 21 | external _act: (unit => Js.undefined>) => unit = "act" 22 | 23 | let act = callback => 24 | _act(() => { 25 | callback() 26 | 27 | // (work-around) BuckleScript compiles `unit` to `0`, this will cause a warning as following: 28 | // Warning: The callback passed to act(...) function must return undefined, or a Promise. 29 | Js.Undefined.empty 30 | }) 31 | 32 | @module("@testing-library/react") 33 | external _render: (React.element, renderOptions) => renderResult = "render" 34 | 35 | @get external container: renderResult => Dom.element = "container" 36 | 37 | @get external baseElement: renderResult => Dom.element = "baseElement" 38 | 39 | @bs.send.pipe(: renderResult) 40 | external _debug: (Js.undefined, Js.undefined) => unit = "debug" 41 | 42 | @bs.send.pipe(: renderResult) external unmount: unit => bool = "unmount" 43 | 44 | @bs.send.pipe(: renderResult) 45 | external rerender: React.element => unit = "rerender" 46 | 47 | @bs.send.pipe(: renderResult) 48 | external asFragment: unit => Dom.element = "asFragment" 49 | 50 | // ByLabelText 51 | @bs.send.pipe(: renderResult) 52 | external _getByLabelText: ( 53 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 54 | ~options: Js.undefined, 55 | ) => Dom.element = "getByLabelText" 56 | 57 | let getByLabelText = (~matcher, ~options=?, result) => 58 | _getByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 59 | 60 | @bs.send.pipe(: renderResult) 61 | external _getAllByLabelText: ( 62 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 63 | ~options: Js.undefined, 64 | ) => array = "getAllByLabelText" 65 | 66 | let getAllByLabelText = (~matcher, ~options=?, result) => 67 | _getAllByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 68 | 69 | @bs.send.pipe(: renderResult) 70 | external _queryByLabelText: ( 71 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 72 | ~options: Js.undefined, 73 | ) => Js.null = "queryByLabelText" 74 | 75 | let queryByLabelText = (~matcher, ~options=?, result) => 76 | _queryByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 77 | 78 | @bs.send.pipe(: renderResult) 79 | external _queryAllByLabelText: ( 80 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 81 | ~options: Js.undefined, 82 | ) => array = "queryAllByLabelText" 83 | 84 | let queryAllByLabelText = (~matcher, ~options=?, result) => 85 | _queryAllByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 86 | 87 | @bs.send.pipe(: renderResult) 88 | external _findByLabelText: ( 89 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 90 | ~options: Js.undefined, 91 | ) => Js.Promise.t = "findByLabelText" 92 | 93 | let findByLabelText = (~matcher, ~options=?, result) => 94 | _findByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 95 | 96 | @bs.send.pipe(: renderResult) 97 | external _findAllByLabelText: ( 98 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 99 | ~options: Js.undefined, 100 | ) => Js.Promise.t> = "findAllByLabelText" 101 | 102 | let findAllByLabelText = (~matcher, ~options=?, result) => 103 | _findAllByLabelText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 104 | 105 | // ByPlaceholderText 106 | @bs.send.pipe(: renderResult) 107 | external _getByPlaceholderText: ( 108 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 109 | ~options: Js.undefined, 110 | ) => Dom.element = "getByPlaceholderText" 111 | 112 | let getByPlaceholderText = (~matcher, ~options=?, result) => 113 | _getByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 114 | 115 | @bs.send.pipe(: renderResult) 116 | external _getAllByPlaceholderText: ( 117 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 118 | ~options: Js.undefined, 119 | ) => array = "getAllByPlaceholderText" 120 | 121 | let getAllByPlaceholderText = (~matcher, ~options=?, result) => 122 | _getAllByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 123 | 124 | @bs.send.pipe(: renderResult) 125 | external _queryByPlaceholderText: ( 126 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 127 | ~options: Js.undefined, 128 | ) => Js.null = "queryByPlaceholderText" 129 | 130 | let queryByPlaceholderText = (~matcher, ~options=?, result) => 131 | _queryByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 132 | 133 | @bs.send.pipe(: renderResult) 134 | external _queryAllByPlaceholderText: ( 135 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 136 | ~options: Js.undefined, 137 | ) => array = "queryAllByPlaceholderText" 138 | 139 | let queryAllByPlaceholderText = (~matcher, ~options=?, result) => 140 | _queryAllByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 141 | 142 | @bs.send.pipe(: renderResult) 143 | external _findByPlaceholderText: ( 144 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 145 | ~options: Js.undefined, 146 | ) => Js.Promise.t = "findByPlaceholderText" 147 | 148 | let findByPlaceholderText = (~matcher, ~options=?, result) => 149 | _findByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 150 | 151 | @bs.send.pipe(: renderResult) 152 | external _findAllByPlaceholderText: ( 153 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 154 | ~options: Js.undefined, 155 | ) => Js.Promise.t> = "findAllByPlaceholderText" 156 | 157 | let findAllByPlaceholderText = (~matcher, ~options=?, result) => 158 | _findAllByPlaceholderText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 159 | 160 | // ByText 161 | @bs.send.pipe(: renderResult) 162 | external _getByText: ( 163 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 164 | ~options: Js.undefined, 165 | ) => Dom.element = "getByText" 166 | 167 | let getByText = (~matcher, ~options=?, result) => 168 | _getByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 169 | 170 | @bs.send.pipe(: renderResult) 171 | external _getAllByText: ( 172 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 173 | ~options: Js.undefined, 174 | ) => array = "getAllByText" 175 | 176 | let getAllByText = (~matcher, ~options=?, result) => 177 | _getAllByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 178 | 179 | @bs.send.pipe(: renderResult) 180 | external _queryByText: ( 181 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 182 | ~options: Js.undefined, 183 | ) => Js.null = "queryByText" 184 | 185 | let queryByText = (~matcher, ~options=?, result) => 186 | _queryByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 187 | 188 | @bs.send.pipe(: renderResult) 189 | external _queryAllByText: ( 190 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 191 | ~options: Js.undefined, 192 | ) => array = "queryAllByText" 193 | 194 | let queryAllByText = (~matcher, ~options=?, result) => 195 | _queryAllByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 196 | 197 | @bs.send.pipe(: renderResult) 198 | external _findByText: ( 199 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 200 | ~options: Js.undefined, 201 | ) => Js.Promise.t = "findByText" 202 | 203 | let findByText = (~matcher, ~options=?, result) => 204 | _findByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 205 | 206 | @bs.send.pipe(: renderResult) 207 | external _findAllByText: ( 208 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 209 | ~options: Js.undefined, 210 | ) => Js.Promise.t> = "findAllByText" 211 | 212 | let findAllByText = (~matcher, ~options=?, result) => 213 | _findAllByText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 214 | 215 | // ByAltText 216 | @bs.send.pipe(: renderResult) 217 | external _getByAltText: ( 218 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 219 | ~options: Js.undefined, 220 | ) => Dom.element = "getByAltText" 221 | 222 | let getByAltText = (~matcher, ~options=?, result) => 223 | _getByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 224 | 225 | @bs.send.pipe(: renderResult) 226 | external _getAllByAltText: ( 227 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 228 | ~options: Js.undefined, 229 | ) => array = "getAllByAltText" 230 | 231 | let getAllByAltText = (~matcher, ~options=?, result) => 232 | _getAllByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 233 | 234 | @bs.send.pipe(: renderResult) 235 | external _queryByAltText: ( 236 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 237 | ~options: Js.undefined, 238 | ) => Js.null = "queryByAltText" 239 | 240 | let queryByAltText = (~matcher, ~options=?, result) => 241 | _queryByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 242 | 243 | @bs.send.pipe(: renderResult) 244 | external _queryAllByAltText: ( 245 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 246 | ~options: Js.undefined, 247 | ) => array = "queryAllByAltText" 248 | 249 | let queryAllByAltText = (~matcher, ~options=?, result) => 250 | _queryAllByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 251 | 252 | @bs.send.pipe(: renderResult) 253 | external _findByAltText: ( 254 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 255 | ~options: Js.undefined, 256 | ) => Js.Promise.t = "findByAltText" 257 | 258 | let findByAltText = (~matcher, ~options=?, result) => 259 | _findByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 260 | 261 | @bs.send.pipe(: renderResult) 262 | external _findAllByAltText: ( 263 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 264 | ~options: Js.undefined, 265 | ) => Js.Promise.t> = "findAllByAltText" 266 | 267 | let findAllByAltText = (~matcher, ~options=?, result) => 268 | _findAllByAltText(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 269 | 270 | // ByTitle 271 | @bs.send.pipe(: renderResult) 272 | external _getByTitle: ( 273 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 274 | ~options: Js.undefined, 275 | ) => Dom.element = "getByTitle" 276 | 277 | let getByTitle = (~matcher, ~options=?, result) => 278 | _getByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 279 | 280 | @bs.send.pipe(: renderResult) 281 | external _getAllByTitle: ( 282 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 283 | ~options: Js.undefined, 284 | ) => array = "getAllByTitle" 285 | 286 | let getAllByTitle = (~matcher, ~options=?, result) => 287 | _getAllByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 288 | 289 | @bs.send.pipe(: renderResult) 290 | external _queryByTitle: ( 291 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 292 | ~options: Js.undefined, 293 | ) => Js.null = "queryByTitle" 294 | 295 | let queryByTitle = (~matcher, ~options=?, result) => 296 | _queryByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 297 | 298 | @bs.send.pipe(: renderResult) 299 | external _queryAllByTitle: ( 300 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 301 | ~options: Js.undefined, 302 | ) => array = "queryAllByTitle" 303 | 304 | let queryAllByTitle = (~matcher, ~options=?, result) => 305 | _queryAllByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 306 | 307 | @bs.send.pipe(: renderResult) 308 | external _findByTitle: ( 309 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 310 | ~options: Js.undefined, 311 | ) => Js.Promise.t = "findByTitle" 312 | 313 | let findByTitle = (~matcher, ~options=?, result) => 314 | _findByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 315 | 316 | @bs.send.pipe(: renderResult) 317 | external _findAllByTitle: ( 318 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 319 | ~options: Js.undefined, 320 | ) => Js.Promise.t> = "findAllByTitle" 321 | 322 | let findAllByTitle = (~matcher, ~options=?, result) => 323 | _findAllByTitle(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 324 | 325 | // ByDisplayValue 326 | @bs.send.pipe(: renderResult) 327 | external _getByDisplayValue: ( 328 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 329 | ~options: Js.undefined, 330 | ) => Dom.element = "getByDisplayValue" 331 | 332 | let getByDisplayValue = (~matcher, ~options=?, result) => 333 | _getByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 334 | 335 | @bs.send.pipe(: renderResult) 336 | external _getAllByDisplayValue: ( 337 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 338 | ~options: Js.undefined, 339 | ) => array = "getAllByDisplayValue" 340 | 341 | let getAllByDisplayValue = (~matcher, ~options=?, result) => 342 | _getAllByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 343 | 344 | @bs.send.pipe(: renderResult) 345 | external _queryByDisplayValue: ( 346 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 347 | ~options: Js.undefined, 348 | ) => Js.null = "queryByDisplayValue" 349 | 350 | let queryByDisplayValue = (~matcher, ~options=?, result) => 351 | _queryByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 352 | 353 | @bs.send.pipe(: renderResult) 354 | external _queryAllByDisplayValue: ( 355 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 356 | ~options: Js.undefined, 357 | ) => array = "queryAllByDisplayValue" 358 | 359 | let queryAllByDisplayValue = (~matcher, ~options=?, result) => 360 | _queryAllByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 361 | 362 | @bs.send.pipe(: renderResult) 363 | external _findByDisplayValue: ( 364 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 365 | ~options: Js.undefined, 366 | ) => Js.Promise.t = "findByDisplayValue" 367 | 368 | let findByDisplayValue = (~matcher, ~options=?, result) => 369 | _findByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 370 | 371 | @bs.send.pipe(: renderResult) 372 | external _findAllByDisplayValue: ( 373 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 374 | ~options: Js.undefined, 375 | ) => Js.Promise.t> = "findAllByDisplayValue" 376 | 377 | let findAllByDisplayValue = (~matcher, ~options=?, result) => 378 | _findAllByDisplayValue(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 379 | 380 | // ByRole 381 | @bs.send.pipe(: renderResult) 382 | external _getByRole: ( 383 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 384 | ~options: Js.undefined, 385 | ) => Dom.element = "getByRole" 386 | 387 | let getByRole = (~matcher, ~options=?, result) => 388 | _getByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 389 | 390 | @bs.send.pipe(: renderResult) 391 | external _getAllByRole: ( 392 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 393 | ~options: Js.undefined, 394 | ) => array = "getAllByRole" 395 | 396 | let getAllByRole = (~matcher, ~options=?, result) => 397 | _getAllByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 398 | 399 | @bs.send.pipe(: renderResult) 400 | external _queryByRole: ( 401 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 402 | ~options: Js.undefined, 403 | ) => Js.null = "queryByRole" 404 | 405 | let queryByRole = (~matcher, ~options=?, result) => 406 | _queryByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 407 | 408 | @bs.send.pipe(: renderResult) 409 | external _queryAllByRole: ( 410 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 411 | ~options: Js.undefined, 412 | ) => array = "queryAllByRole" 413 | 414 | let queryAllByRole = (~matcher, ~options=?, result) => 415 | _queryAllByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 416 | 417 | @bs.send.pipe(: renderResult) 418 | external _findByRole: ( 419 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 420 | ~options: Js.undefined, 421 | ) => Js.Promise.t = "findByRole" 422 | 423 | let findByRole = (~matcher, ~options=?, result) => 424 | _findByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 425 | 426 | @bs.send.pipe(: renderResult) 427 | external _findAllByRole: ( 428 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 429 | ~options: Js.undefined, 430 | ) => Js.Promise.t> = "findAllByRole" 431 | 432 | let findAllByRole = (~matcher, ~options=?, result) => 433 | _findAllByRole(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 434 | 435 | // ByTestId 436 | @bs.send.pipe(: renderResult) 437 | external _getByTestId: ( 438 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 439 | ~options: Js.undefined, 440 | ) => Dom.element = "getByTestId" 441 | 442 | let getByTestId = (~matcher, ~options=?, result) => 443 | _getByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 444 | 445 | @bs.send.pipe(: renderResult) 446 | external _getAllByTestId: ( 447 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 448 | ~options: Js.undefined, 449 | ) => array = "getAllByTestId" 450 | 451 | let getAllByTestId = (~matcher, ~options=?, result) => 452 | _getAllByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 453 | 454 | @bs.send.pipe(: renderResult) 455 | external _queryByTestId: ( 456 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 457 | ~options: Js.undefined, 458 | ) => Js.null = "queryByTestId" 459 | 460 | let queryByTestId = (~matcher, ~options=?, result) => 461 | _queryByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 462 | 463 | @bs.send.pipe(: renderResult) 464 | external _queryAllByTestId: ( 465 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 466 | ~options: Js.undefined, 467 | ) => array = "queryAllByTestId" 468 | 469 | let queryAllByTestId = (~matcher, ~options=?, result) => 470 | _queryAllByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 471 | 472 | @bs.send.pipe(: renderResult) 473 | external _findByTestId: ( 474 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 475 | ~options: Js.undefined, 476 | ) => Js.Promise.t = "findByTestId" 477 | 478 | let findByTestId = (~matcher, ~options=?, result) => 479 | _findByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 480 | 481 | @bs.send.pipe(: renderResult) 482 | external _findAllByTestId: ( 483 | ~matcher: @unwrap [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 484 | ~options: Js.undefined, 485 | ) => Js.Promise.t> = "findAllByTestId" 486 | 487 | let findAllByTestId = (~matcher, ~options=?, result) => 488 | _findAllByTestId(result, ~matcher, ~options=Js.Undefined.fromOption(options)) 489 | 490 | let render = (~baseElement=?, ~container=?, ~hydrate=?, ~wrapper=?, ~queries=?, element) => { 491 | let baseElement_ = switch container { 492 | | Some(container') => Js.Undefined.return(container') 493 | | None => Js.Undefined.fromOption(baseElement) 494 | } 495 | let container_ = Js.Undefined.fromOption(container) 496 | 497 | _render( 498 | element, 499 | { 500 | "baseElement": baseElement_, 501 | "container": container_, 502 | "hydrate": Js.Undefined.fromOption(hydrate), 503 | "wrapper": Js.Undefined.fromOption(wrapper), 504 | "queries": Js.Undefined.fromOption(queries), 505 | }, 506 | ) 507 | } 508 | 509 | let debug = (~el=?, ~maxLengthToPrint=?, ()) => 510 | _debug(Js.Undefined.fromOption(el), Js.Undefined.fromOption(maxLengthToPrint)) 511 | -------------------------------------------------------------------------------- /src/ReactTestingLibrary.resi: -------------------------------------------------------------------------------- 1 | module FireEvent: { 2 | let abort: (~eventInit: {..}=?, Dom.element) => unit 3 | let animationEnd: (~eventInit: {..}=?, Dom.element) => unit 4 | let animationIteration: (~eventInit: {..}=?, Dom.element) => unit 5 | let animationStart: (~eventInit: {..}=?, Dom.element) => unit 6 | let blur: (~eventInit: {..}=?, Dom.element) => unit 7 | let canPlay: (~eventInit: {..}=?, Dom.element) => unit 8 | let canPlayThrough: (~eventInit: {..}=?, Dom.element) => unit 9 | let change: (~eventInit: {..}=?, Dom.element) => unit 10 | let click: (~eventInit: {..}=?, Dom.element) => unit 11 | let compositionEnd: (~eventInit: {..}=?, Dom.element) => unit 12 | let compositionStart: (~eventInit: {..}=?, Dom.element) => unit 13 | let compositionUpdate: (~eventInit: {..}=?, Dom.element) => unit 14 | let contextMenu: (~eventInit: {..}=?, Dom.element) => unit 15 | let copy: (~eventInit: {..}=?, Dom.element) => unit 16 | let cut: (~eventInit: {..}=?, Dom.element) => unit 17 | let dblClick: (~eventInit: {..}=?, Dom.element) => unit 18 | let doubleClick: (~eventInit: {..}=?, Dom.element) => unit 19 | let drag: (~eventInit: {..}=?, Dom.element) => unit 20 | let dragEnd: (~eventInit: {..}=?, Dom.element) => unit 21 | let dragEnter: (~eventInit: {..}=?, Dom.element) => unit 22 | let dragExit: (~eventInit: {..}=?, Dom.element) => unit 23 | let dragLeave: (~eventInit: {..}=?, Dom.element) => unit 24 | let dragOver: (~eventInit: {..}=?, Dom.element) => unit 25 | let dragStart: (~eventInit: {..}=?, Dom.element) => unit 26 | let drop: (~eventInit: {..}=?, Dom.element) => unit 27 | let durationChange: (~eventInit: {..}=?, Dom.element) => unit 28 | let emptied: (~eventInit: {..}=?, Dom.element) => unit 29 | let encrypted: (~eventInit: {..}=?, Dom.element) => unit 30 | let ended: (~eventInit: {..}=?, Dom.element) => unit 31 | let error: (~eventInit: {..}=?, Dom.element) => unit 32 | let focus: (~eventInit: {..}=?, Dom.element) => unit 33 | let focusIn: (~eventInit: {..}=?, Dom.element) => unit 34 | let focusOut: (~eventInit: {..}=?, Dom.element) => unit 35 | let input: (~eventInit: {..}=?, Dom.element) => unit 36 | let invalid: (~eventInit: {..}=?, Dom.element) => unit 37 | let keyDown: (~eventInit: {..}=?, Dom.element) => unit 38 | let keyPress: (~eventInit: {..}=?, Dom.element) => unit 39 | let keyUp: (~eventInit: {..}=?, Dom.element) => unit 40 | let load: (~eventInit: {..}=?, Dom.element) => unit 41 | let loadStart: (~eventInit: {..}=?, Dom.element) => unit 42 | let loadedData: (~eventInit: {..}=?, Dom.element) => unit 43 | let loadedMetadata: (~eventInit: {..}=?, Dom.element) => unit 44 | let mouseDown: (~eventInit: {..}=?, Dom.element) => unit 45 | let mouseEnter: (~eventInit: {..}=?, Dom.element) => unit 46 | let mouseLeave: (~eventInit: {..}=?, Dom.element) => unit 47 | let mouseMove: (~eventInit: {..}=?, Dom.element) => unit 48 | let mouseOut: (~eventInit: {..}=?, Dom.element) => unit 49 | let mouseOver: (~eventInit: {..}=?, Dom.element) => unit 50 | let mouseUp: (~eventInit: {..}=?, Dom.element) => unit 51 | let paste: (~eventInit: {..}=?, Dom.element) => unit 52 | let pause: (~eventInit: {..}=?, Dom.element) => unit 53 | let play: (~eventInit: {..}=?, Dom.element) => unit 54 | let playing: (~eventInit: {..}=?, Dom.element) => unit 55 | let progress: (~eventInit: {..}=?, Dom.element) => unit 56 | let rateChange: (~eventInit: {..}=?, Dom.element) => unit 57 | let scroll: (~eventInit: {..}=?, Dom.element) => unit 58 | let seeked: (~eventInit: {..}=?, Dom.element) => unit 59 | let seeking: (~eventInit: {..}=?, Dom.element) => unit 60 | let select: (~eventInit: {..}=?, Dom.element) => unit 61 | let stalled: (~eventInit: {..}=?, Dom.element) => unit 62 | let submit: (~eventInit: {..}=?, Dom.element) => unit 63 | let suspend: (~eventInit: {..}=?, Dom.element) => unit 64 | let timeUpdate: (~eventInit: {..}=?, Dom.element) => unit 65 | let touchCancel: (~eventInit: {..}=?, Dom.element) => unit 66 | let touchEnd: (~eventInit: {..}=?, Dom.element) => unit 67 | let touchMove: (~eventInit: {..}=?, Dom.element) => unit 68 | let touchStart: (~eventInit: {..}=?, Dom.element) => unit 69 | let transitionEnd: (~eventInit: {..}=?, Dom.element) => unit 70 | let volumeChange: (~eventInit: {..}=?, Dom.element) => unit 71 | let waiting: (~eventInit: {..}=?, Dom.element) => unit 72 | let wheel: (~eventInit: {..}=?, Dom.element) => unit 73 | } 74 | 75 | type renderResult 76 | type queries 77 | type renderOptions = { 78 | "container": Js.undefined, 79 | "baseElement": Js.undefined, 80 | "hydrate": Js.undefined, 81 | "wrapper": Js.undefined, 82 | "queries": Js.undefined, 83 | } 84 | 85 | @bs.module("@testing-library/react") 86 | external cleanup: unit => unit = "cleanup" 87 | 88 | let act: (unit => unit) => unit 89 | 90 | @bs.get external container: renderResult => Dom.element = "container" 91 | 92 | @bs.get external baseElement: renderResult => Dom.element = "baseElement" 93 | 94 | @bs.send.pipe(: renderResult) external unmount: unit => bool = "unmount" 95 | 96 | @bs.send.pipe(: renderResult) 97 | external asFragment: unit => Dom.element = "asFragment" 98 | 99 | // ByLabelText 100 | let getByLabelText: ( 101 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 102 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 103 | renderResult, 104 | ) => Dom.element 105 | 106 | let getAllByLabelText: ( 107 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 108 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 109 | renderResult, 110 | ) => array 111 | 112 | let queryByLabelText: ( 113 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 114 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 115 | renderResult, 116 | ) => Js.null 117 | 118 | let queryAllByLabelText: ( 119 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 120 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 121 | renderResult, 122 | ) => array 123 | 124 | let findByLabelText: ( 125 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 126 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 127 | renderResult, 128 | ) => Js.Promise.t 129 | 130 | let findAllByLabelText: ( 131 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 132 | ~options: DomTestingLibrary.ByLabelTextQuery.options=?, 133 | renderResult, 134 | ) => Js.Promise.t> 135 | 136 | // ByPlaceholderText 137 | let getByPlaceholderText: ( 138 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 139 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 140 | renderResult, 141 | ) => Dom.element 142 | 143 | let getAllByPlaceholderText: ( 144 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 145 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 146 | renderResult, 147 | ) => array 148 | 149 | let queryByPlaceholderText: ( 150 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 151 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 152 | renderResult, 153 | ) => Js.null 154 | 155 | let queryAllByPlaceholderText: ( 156 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 157 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 158 | renderResult, 159 | ) => array 160 | 161 | let findByPlaceholderText: ( 162 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 163 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 164 | renderResult, 165 | ) => Js.Promise.t 166 | 167 | let findAllByPlaceholderText: ( 168 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 169 | ~options: DomTestingLibrary.ByPlaceholderTextQuery.options=?, 170 | renderResult, 171 | ) => Js.Promise.t> 172 | 173 | // ByText 174 | let getByText: ( 175 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 176 | ~options: DomTestingLibrary.ByTextQuery.options=?, 177 | renderResult, 178 | ) => Dom.element 179 | 180 | let getAllByText: ( 181 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 182 | ~options: DomTestingLibrary.ByTextQuery.options=?, 183 | renderResult, 184 | ) => array 185 | 186 | let queryByText: ( 187 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 188 | ~options: DomTestingLibrary.ByTextQuery.options=?, 189 | renderResult, 190 | ) => Js.null 191 | 192 | let queryAllByText: ( 193 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 194 | ~options: DomTestingLibrary.ByTextQuery.options=?, 195 | renderResult, 196 | ) => array 197 | 198 | let findByText: ( 199 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 200 | ~options: DomTestingLibrary.ByTextQuery.options=?, 201 | renderResult, 202 | ) => Js.Promise.t 203 | 204 | let findAllByText: ( 205 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 206 | ~options: DomTestingLibrary.ByTextQuery.options=?, 207 | renderResult, 208 | ) => Js.Promise.t> 209 | 210 | // ByAltText 211 | let getByAltText: ( 212 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 213 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 214 | renderResult, 215 | ) => Dom.element 216 | 217 | let getAllByAltText: ( 218 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 219 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 220 | renderResult, 221 | ) => array 222 | 223 | let queryByAltText: ( 224 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 225 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 226 | renderResult, 227 | ) => Js.null 228 | 229 | let queryAllByAltText: ( 230 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 231 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 232 | renderResult, 233 | ) => array 234 | 235 | let findByAltText: ( 236 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 237 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 238 | renderResult, 239 | ) => Js.Promise.t 240 | 241 | let findAllByAltText: ( 242 | ~matcher: [#Func((string, Dom.element) => bool) | #RegExp(Js.Re.t) | #Str(string)], 243 | ~options: DomTestingLibrary.ByAltTextQuery.options=?, 244 | renderResult, 245 | ) => Js.Promise.t> 246 | 247 | // ByTitle 248 | let getByTitle: ( 249 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 250 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 251 | renderResult, 252 | ) => Dom.element 253 | 254 | let getAllByTitle: ( 255 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 256 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 257 | renderResult, 258 | ) => array 259 | 260 | let queryByTitle: ( 261 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 262 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 263 | renderResult, 264 | ) => Js.null 265 | 266 | let queryAllByTitle: ( 267 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 268 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 269 | renderResult, 270 | ) => array 271 | 272 | let findByTitle: ( 273 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 274 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 275 | renderResult, 276 | ) => Js.Promise.t 277 | 278 | let findAllByTitle: ( 279 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 280 | ~options: DomTestingLibrary.ByTitleQuery.options=?, 281 | renderResult, 282 | ) => Js.Promise.t> 283 | 284 | // ByDisplayValue 285 | let getByDisplayValue: ( 286 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 287 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 288 | renderResult, 289 | ) => Dom.element 290 | 291 | let getAllByDisplayValue: ( 292 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 293 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 294 | renderResult, 295 | ) => array 296 | 297 | let queryByDisplayValue: ( 298 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 299 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 300 | renderResult, 301 | ) => Js.null 302 | 303 | let queryAllByDisplayValue: ( 304 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 305 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 306 | renderResult, 307 | ) => array 308 | 309 | let findByDisplayValue: ( 310 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 311 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 312 | renderResult, 313 | ) => Js.Promise.t 314 | 315 | let findAllByDisplayValue: ( 316 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 317 | ~options: DomTestingLibrary.ByDisplayValueQuery.options=?, 318 | renderResult, 319 | ) => Js.Promise.t> 320 | 321 | // ByRole 322 | let getByRole: ( 323 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 324 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 325 | renderResult, 326 | ) => Dom.element 327 | 328 | let getAllByRole: ( 329 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 330 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 331 | renderResult, 332 | ) => array 333 | 334 | let queryByRole: ( 335 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 336 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 337 | renderResult, 338 | ) => Js.null 339 | 340 | let queryAllByRole: ( 341 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 342 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 343 | renderResult, 344 | ) => array 345 | 346 | let findByRole: ( 347 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 348 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 349 | renderResult, 350 | ) => Js.Promise.t 351 | 352 | let findAllByRole: ( 353 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 354 | ~options: DomTestingLibrary.ByRoleQuery.options=?, 355 | renderResult, 356 | ) => Js.Promise.t> 357 | 358 | // ByTestId 359 | let getByTestId: ( 360 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 361 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 362 | renderResult, 363 | ) => Dom.element 364 | 365 | let getAllByTestId: ( 366 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 367 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 368 | renderResult, 369 | ) => array 370 | 371 | let queryByTestId: ( 372 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 373 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 374 | renderResult, 375 | ) => Js.null 376 | 377 | let queryAllByTestId: ( 378 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 379 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 380 | renderResult, 381 | ) => array 382 | 383 | let findByTestId: ( 384 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 385 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 386 | renderResult, 387 | ) => Js.Promise.t 388 | 389 | let findAllByTestId: ( 390 | ~matcher: [#Str(string) | #RegExp(Js.Re.t) | #Func((string, Dom.element) => bool)], 391 | ~options: DomTestingLibrary.ByTestIdQuery.options=?, 392 | renderResult, 393 | ) => Js.Promise.t> 394 | 395 | @bs.send.pipe(: renderResult) 396 | external rerender: React.element => unit = "rerender" 397 | 398 | let render: ( 399 | ~baseElement: Dom.element=?, 400 | ~container: Dom.element=?, 401 | ~hydrate: bool=?, 402 | ~wrapper: Dom.element=?, 403 | ~queries: queries=?, 404 | React.element, 405 | ) => renderResult 406 | 407 | let debug: (~el: Dom.element=?, ~maxLengthToPrint: int=?, unit, renderResult) => unit 408 | -------------------------------------------------------------------------------- /src/__tests__/ReactTestingLibrary_test.res: -------------------------------------------------------------------------------- 1 | open Jest 2 | 3 | module Greeting = { 4 | @react.component 5 | let make = (~message) =>
{React.string(message)}
6 | } 7 | 8 | module Counter = { 9 | type action = 10 | | Inc 11 | | Dec 12 | 13 | @react.component 14 | let make = () => { 15 | let (state, dispatch) = React.useReducer((state, action) => 16 | switch action { 17 | | Inc => state + 1 18 | | Dec => state - 1 19 | } 20 | , 0) 21 | 22 |
23 | {React.string("Count: " ++ string_of_int(state))} 24 | 25 | 26 |
27 | } 28 | } 29 | 30 | external unsafeAsElement: Dom.node => Dom.element = "%identity" 31 | @get external firstChild: Dom.element => Dom.node = "firstChild" 32 | @get external innerHTML: Dom.node => string = "innerHTML" 33 | 34 | describe("ReactTestingLibrary", () => { 35 | open ReactTestingLibrary 36 | open Expect 37 | 38 | let element = 39 |
40 | {React.cloneElement( 41 |

, 42 | {"data-testid": "h1-heading", "children": [React.string("Heading")]}, 43 | )} 44 |

45 | 46 | test("render works", () => element |> render |> expect |> toMatchSnapshot) 47 | 48 | // ByLabelText 49 | describe("ByLabelText", () => { 50 | let labelText = 51 |
52 | 53 | 54 |
55 | 56 | test("getByLabelText works", () => 57 | labelText |> render |> getByLabelText(~matcher=#Str("Username")) |> expect |> toMatchSnapshot 58 | ) 59 | 60 | test("getAllByLabelText works", () => 61 | labelText 62 | |> render 63 | |> getAllByLabelText(~matcher=#Str("Username")) 64 | |> expect 65 | |> toMatchSnapshot 66 | ) 67 | 68 | test("queryByLabelText works", () => 69 | labelText 70 | |> render 71 | |> queryByLabelText(~matcher=#Str("Username")) 72 | |> expect 73 | |> toMatchSnapshot 74 | ) 75 | 76 | test("queryByLabelText works (element not found)", () => 77 | labelText 78 | |> render 79 | |> queryByLabelText(~matcher=#Str("!@#$Username!@#$")) 80 | |> expect 81 | |> toMatchSnapshot 82 | ) 83 | 84 | test("queryAllByLabelText works", () => 85 | labelText 86 | |> render 87 | |> queryAllByLabelText(~matcher=#Str("Username")) 88 | |> expect 89 | |> toMatchSnapshot 90 | ) 91 | 92 | testPromise("findByLabelText works", () => 93 | labelText 94 | |> render 95 | |> findByLabelText(~matcher=#Str("Username")) 96 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 97 | ) 98 | 99 | testPromise("findAllByLabelText works", () => 100 | labelText 101 | |> render 102 | |> findAllByLabelText(~matcher=#Str("Username")) 103 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 104 | ) 105 | }) 106 | 107 | // ByPlaceholderText 108 | describe("ByPlaceholderText", () => { 109 | let placeholderText = 110 |
111 | 112 | test("getByPlaceholderText works", () => 113 | placeholderText 114 | |> render 115 | |> getByPlaceholderText(~matcher=#Str("Username")) 116 | |> expect 117 | |> toMatchSnapshot 118 | ) 119 | 120 | test("getAllByPlaceholderText works", () => 121 | placeholderText 122 | |> render 123 | |> getAllByPlaceholderText(~matcher=#Str("Username")) 124 | |> expect 125 | |> toMatchSnapshot 126 | ) 127 | 128 | test("queryByPlaceholderText works", () => 129 | placeholderText 130 | |> render 131 | |> queryByPlaceholderText(~matcher=#Str("Username")) 132 | |> expect 133 | |> toMatchSnapshot 134 | ) 135 | 136 | test("queryByPlaceholderText works (element not found)", () => 137 | placeholderText 138 | |> render 139 | |> queryByPlaceholderText(~matcher=#Str("!@#$Username!@#$")) 140 | |> expect 141 | |> toMatchSnapshot 142 | ) 143 | 144 | test("queryAllByPlaceholderText works", () => 145 | placeholderText 146 | |> render 147 | |> queryAllByPlaceholderText(~matcher=#Str("Username")) 148 | |> expect 149 | |> toMatchSnapshot 150 | ) 151 | 152 | testPromise("findByPlaceholderText works", () => 153 | placeholderText 154 | |> render 155 | |> findByPlaceholderText(~matcher=#Str("Username")) 156 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 157 | ) 158 | 159 | testPromise("findAllByPlaceholderText works", () => 160 | placeholderText 161 | |> render 162 | |> findAllByPlaceholderText(~matcher=#Str("Username")) 163 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 164 | ) 165 | }) 166 | 167 | // ByText 168 | describe("ByText", () => { 169 | let text = 170 | 171 | test("getByText works", () => 172 | text |> render |> getByText(~matcher=#Str(j`About ℹ️`)) |> expect |> toMatchSnapshot 173 | ) 174 | 175 | test("getAllByText works", () => 176 | text |> render |> getAllByText(~matcher=#Str(j`About ℹ️`)) |> expect |> toMatchSnapshot 177 | ) 178 | 179 | test("queryByText works", () => 180 | text |> render |> queryByText(~matcher=#Str(j`About ℹ️`)) |> expect |> toMatchSnapshot 181 | ) 182 | 183 | test("queryByText works (element not found)", () => 184 | text 185 | |> render 186 | |> queryByText(~matcher=#Str(j`!@#About ℹ️!@#`)) 187 | |> expect 188 | |> toMatchSnapshot 189 | ) 190 | 191 | test("queryAllByText works", () => 192 | text |> render |> queryAllByText(~matcher=#Str(j`About ℹ️`)) |> expect |> toMatchSnapshot 193 | ) 194 | 195 | testPromise("findByText works", () => 196 | text 197 | |> render 198 | |> findByText(~matcher=#Str(j`About ℹ️`)) 199 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 200 | ) 201 | 202 | testPromise("findAllByText works", () => 203 | text 204 | |> render 205 | |> findAllByText(~matcher=#Str(j`About ℹ️`)) 206 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 207 | ) 208 | }) 209 | 210 | // ByAltText 211 | describe("ByAltText", () => { 212 | let altText = 213 |
214 | Incredibles 1 Poster 215 | Incredibles 2 Poster 216 |
217 | 218 | test("getByAltText works", () => 219 | altText 220 | |> render 221 | |> getByAltText(~matcher=#Str("Incredibles 2 Poster")) 222 | |> expect 223 | |> toMatchSnapshot 224 | ) 225 | 226 | test("getAllByAltText works", () => 227 | altText 228 | |> render 229 | |> getAllByAltText(~matcher=#Str("Incredibles 2 Poster")) 230 | |> expect 231 | |> toMatchSnapshot 232 | ) 233 | 234 | test("queryByAltText works", () => 235 | altText 236 | |> render 237 | |> queryByAltText(~matcher=#Str("Incredibles 2 Poster")) 238 | |> expect 239 | |> toMatchSnapshot 240 | ) 241 | 242 | test("queryByAltText works (element not found)", () => 243 | altText 244 | |> render 245 | |> queryByAltText(~matcher=#Str("!@#$Incredibles 2 Poster!@#$")) 246 | |> expect 247 | |> toMatchSnapshot 248 | ) 249 | 250 | test("queryAllByAltText works", () => 251 | altText 252 | |> render 253 | |> queryAllByAltText(~matcher=#Str("Incredibles 2 Poster")) 254 | |> expect 255 | |> toMatchSnapshot 256 | ) 257 | 258 | testPromise("findByAltText works", () => 259 | altText 260 | |> render 261 | |> findByAltText(~matcher=#Str("Incredibles 2 Poster")) 262 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 263 | ) 264 | 265 | testPromise("findAllByAltText works", () => 266 | altText 267 | |> render 268 | |> findAllByAltText(~matcher=#Str("Incredibles 2 Poster")) 269 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 270 | ) 271 | }) 272 | 273 | // ByTitle 274 | describe("ByTitle", () => { 275 | let title = 276 |
277 | 278 | {React.string("Close")} 279 |
280 | 281 | test("getByTitle works", () => 282 | title |> render |> getByTitle(~matcher=#Str("Delete")) |> expect |> toMatchSnapshot 283 | ) 284 | 285 | test("getAllByTitle works", () => 286 | title |> render |> getAllByTitle(~matcher=#Str("Delete")) |> expect |> toMatchSnapshot 287 | ) 288 | 289 | test("queryByTitle works", () => 290 | title |> render |> queryByTitle(~matcher=#Str("Delete")) |> expect |> toMatchSnapshot 291 | ) 292 | 293 | test("queryByTitle works (element not found)", () => 294 | title |> render |> queryByTitle(~matcher=#Str("!@#$Delete!@#$")) |> expect |> toMatchSnapshot 295 | ) 296 | 297 | test("queryAllByTitle works", () => 298 | title |> render |> queryAllByTitle(~matcher=#Str("Delete")) |> expect |> toMatchSnapshot 299 | ) 300 | 301 | testPromise("findByTitle works", () => 302 | title 303 | |> render 304 | |> findByTitle(~matcher=#Str("Delete")) 305 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 306 | ) 307 | 308 | testPromise("findAllByTitle works", () => 309 | title 310 | |> render 311 | |> findAllByTitle(~matcher=#Str("Delete")) 312 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 313 | ) 314 | }) 315 | 316 | // ByDisplayValue 317 | describe("ByDisplayValue", () => { 318 | let title =
319 | 320 | test("getByDisplayValue works", () => 321 | title |> render |> getByDisplayValue(~matcher=#Str("ReasonML")) |> expect |> toMatchSnapshot 322 | ) 323 | 324 | test("getAllByDisplayValue works", () => 325 | title 326 | |> render 327 | |> getAllByDisplayValue(~matcher=#Str("ReasonML")) 328 | |> expect 329 | |> toMatchSnapshot 330 | ) 331 | 332 | test("queryByDisplayValue works", () => 333 | title |> render |> queryByDisplayValue(~matcher=#Str("ReasonML")) |> expect |> toMatchSnapshot 334 | ) 335 | 336 | test("queryByDisplayValue works (element not found)", () => 337 | title 338 | |> render 339 | |> queryByDisplayValue(~matcher=#Str("!@#$ReasonML!@#$")) 340 | |> expect 341 | |> toMatchSnapshot 342 | ) 343 | 344 | test("queryAllByDisplayValue works", () => 345 | title 346 | |> render 347 | |> queryAllByDisplayValue(~matcher=#Str("ReasonML")) 348 | |> expect 349 | |> toMatchSnapshot 350 | ) 351 | 352 | testPromise("findByDisplayValue works", () => 353 | title 354 | |> render 355 | |> findByDisplayValue(~matcher=#Str("ReasonML")) 356 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 357 | ) 358 | 359 | testPromise("findAllByDisplayValue works", () => 360 | title 361 | |> render 362 | |> findAllByDisplayValue(~matcher=#Str("ReasonML")) 363 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 364 | ) 365 | }) 366 | 367 | // ByRole 368 | describe("ByRole", () => { 369 | let role = 370 |
371 | 372 | 373 |
374 | 375 | test("getByRole works", () => 376 | role |> render |> getByRole(~matcher=#Str("button")) |> expect |> toMatchSnapshot 377 | ) 378 | 379 | test("getAllByRole works", () => 380 | role |> render |> getAllByRole(~matcher=#Str("button")) |> expect |> toMatchSnapshot 381 | ) 382 | 383 | test("queryByRole works", () => 384 | role |> render |> queryByRole(~matcher=#Str("button")) |> expect |> toMatchSnapshot 385 | ) 386 | 387 | test("queryByRole works (element not found)", () => 388 | role |> render |> queryByRole(~matcher=#Str("!@#$button!@#$")) |> expect |> toMatchSnapshot 389 | ) 390 | 391 | test("queryAllByRole works", () => 392 | role |> render |> queryAllByRole(~matcher=#Str("button")) |> expect |> toMatchSnapshot 393 | ) 394 | 395 | testPromise("findByRole works", () => 396 | role 397 | |> render 398 | |> findByRole(~matcher=#Str("button")) 399 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 400 | ) 401 | 402 | testPromise("findAllByRole works", () => 403 | role 404 | |> render 405 | |> findAllByRole(~matcher=#Str("button")) 406 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 407 | ) 408 | }) 409 | 410 | // ByTestId 411 | describe("ByTestId", () => { 412 | test("getByTestId works", () => 413 | element |> render |> getByTestId(~matcher=#Str("h1-heading")) |> expect |> toMatchSnapshot 414 | ) 415 | 416 | test("getAllByTestId works", () => 417 | element |> render |> getAllByTestId(~matcher=#Str("h1-heading")) |> expect |> toMatchSnapshot 418 | ) 419 | 420 | test("queryByTestId works", () => 421 | element |> render |> queryByTestId(~matcher=#Str("h1-heading")) |> expect |> toMatchSnapshot 422 | ) 423 | 424 | test("queryByTestId works (element not found)", () => 425 | element 426 | |> render 427 | |> queryByTestId(~matcher=#Str("!@#$h1-heading!@#$")) 428 | |> expect 429 | |> toMatchSnapshot 430 | ) 431 | 432 | test("queryAllByTestId works", () => 433 | element 434 | |> render 435 | |> queryAllByTestId(~matcher=#Str("h1-heading")) 436 | |> expect 437 | |> toMatchSnapshot 438 | ) 439 | 440 | testPromise("findByTestId works", () => 441 | element 442 | |> render 443 | |> findByTestId(~matcher=#Str("h1-heading")) 444 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 445 | ) 446 | 447 | testPromise("findAllByTestId works", () => 448 | element 449 | |> render 450 | |> findAllByTestId(~matcher=#Str("h1-heading")) 451 | |> Js.Promise.then_(result => result |> expect |> toMatchSnapshot |> Js.Promise.resolve) 452 | ) 453 | }) 454 | 455 | describe("debug", () => { 456 | beforeEach(() => { 457 | let _ = %raw(`jest.spyOn(console, 'log').mockImplementation(() => {})`) 458 | }) 459 | 460 | afterEach(() => { 461 | let _ = %raw(`console.log.mockRestore()`) 462 | }) 463 | 464 | test("works", () => { 465 | let _ = element |> render |> debug() 466 | 467 | let _ = %raw(`expect(console.log).toHaveBeenCalledTimes(1)`) 468 | let _ = %raw(` 469 | expect(console.log).toHaveBeenCalledWith( 470 | expect.stringContaining('Heading') 471 | ) 472 | `) 473 | 474 | pass 475 | }) 476 | 477 | test("works with element argument", () => { 478 | let result = element |> render 479 | let el = result |> container |> firstChild |> unsafeAsElement 480 | 481 | let _ = result |> debug(~el, ()) 482 | 483 | let _ = %raw(`expect(console.log).toHaveBeenCalledTimes(1)`) 484 | let _ = %raw(` 485 | expect(console.log).toHaveBeenCalledWith( 486 | expect.stringContaining('Heading') 487 | ) 488 | `) 489 | 490 | pass 491 | }) 492 | 493 | test("works with maxLengthToPrint argument", () => { 494 | let result = element |> render 495 | let el = result |> container |> firstChild |> unsafeAsElement 496 | 497 | let _ = result |> debug(~el, ~maxLengthToPrint=25, ()) 498 | 499 | let _ = %raw(`expect(console.log).toHaveBeenCalledTimes(1)`) 500 | let _ = %raw(` 501 | expect(console.log).toHaveBeenCalledWith( 502 | expect.stringContaining('sty...') 503 | ) 504 | `) 505 | 506 | pass 507 | }) 508 | }) 509 | 510 | test("rerender works", () => { 511 | let result = render() 512 | let check = text => result |> container |> firstChild |> innerHTML |> expect |> toEqual(text) 513 | 514 | check("hi") |> ignore 515 | 516 | result |> rerender() 517 | 518 | check("hey") 519 | }) 520 | 521 | test("asFragment works", () => element |> render |> asFragment() |> expect |> toMatchSnapshot) 522 | 523 | test("act works", () => { 524 | let result = |> render 525 | 526 | act(() => result |> getByText(~matcher=#Str("+")) |> FireEvent.click |> ignore) 527 | 528 | result |> getByText(~matcher=#Str("Count: 1")) |> expect |> toMatchSnapshot 529 | }) 530 | 531 | testPromise("Cleaunp, (element not found)", () => { 532 | let result = element |> render 533 | 534 | cleanup() 535 | 536 | Js.Promise.resolve( 537 | result |> queryByTestId(~matcher=#Str("h1-heading")) |> expect |> toMatchSnapshot, 538 | ) 539 | }) 540 | }) 541 | -------------------------------------------------------------------------------- /src/__tests__/__snapshots__/ReactTestingLibrary_test.bs.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`ReactTestingLibrary ByAltText findAllByAltText works 1`] = ` 4 | Array [ 5 | Incredibles 2 Poster, 9 | ] 10 | `; 11 | 12 | exports[`ReactTestingLibrary ByAltText findByAltText works 1`] = ` 13 | Incredibles 2 Poster 17 | `; 18 | 19 | exports[`ReactTestingLibrary ByAltText getAllByAltText works 1`] = ` 20 | Array [ 21 | Incredibles 2 Poster, 25 | ] 26 | `; 27 | 28 | exports[`ReactTestingLibrary ByAltText getByAltText works 1`] = ` 29 | Incredibles 2 Poster 33 | `; 34 | 35 | exports[`ReactTestingLibrary ByAltText queryAllByAltText works 1`] = ` 36 | Array [ 37 | Incredibles 2 Poster, 41 | ] 42 | `; 43 | 44 | exports[`ReactTestingLibrary ByAltText queryByAltText works (element not found) 1`] = `null`; 45 | 46 | exports[`ReactTestingLibrary ByAltText queryByAltText works 1`] = ` 47 | Incredibles 2 Poster 51 | `; 52 | 53 | exports[`ReactTestingLibrary ByDisplayValue findAllByDisplayValue works 1`] = ` 54 | Array [ 55 | , 60 | ] 61 | `; 62 | 63 | exports[`ReactTestingLibrary ByDisplayValue findByDisplayValue works 1`] = ` 64 | 69 | `; 70 | 71 | exports[`ReactTestingLibrary ByDisplayValue getAllByDisplayValue works 1`] = ` 72 | Array [ 73 | , 78 | ] 79 | `; 80 | 81 | exports[`ReactTestingLibrary ByDisplayValue getByDisplayValue works 1`] = ` 82 | 87 | `; 88 | 89 | exports[`ReactTestingLibrary ByDisplayValue queryAllByDisplayValue works 1`] = ` 90 | Array [ 91 | , 96 | ] 97 | `; 98 | 99 | exports[`ReactTestingLibrary ByDisplayValue queryByDisplayValue works (element not found) 1`] = `null`; 100 | 101 | exports[`ReactTestingLibrary ByDisplayValue queryByDisplayValue works 1`] = ` 102 | 107 | `; 108 | 109 | exports[`ReactTestingLibrary ByLabelText findAllByLabelText works 1`] = ` 110 | Array [ 111 | , 114 | ] 115 | `; 116 | 117 | exports[`ReactTestingLibrary ByLabelText findByLabelText works 1`] = ` 118 | 121 | `; 122 | 123 | exports[`ReactTestingLibrary ByLabelText getAllByLabelText works 1`] = ` 124 | Array [ 125 | , 128 | ] 129 | `; 130 | 131 | exports[`ReactTestingLibrary ByLabelText getByLabelText works 1`] = ` 132 | 135 | `; 136 | 137 | exports[`ReactTestingLibrary ByLabelText queryAllByLabelText works 1`] = ` 138 | Array [ 139 | , 142 | ] 143 | `; 144 | 145 | exports[`ReactTestingLibrary ByLabelText queryByLabelText works (element not found) 1`] = `null`; 146 | 147 | exports[`ReactTestingLibrary ByLabelText queryByLabelText works 1`] = ` 148 | 151 | `; 152 | 153 | exports[`ReactTestingLibrary ByPlaceholderText findAllByPlaceholderText works 1`] = ` 154 | Array [ 155 | , 158 | ] 159 | `; 160 | 161 | exports[`ReactTestingLibrary ByPlaceholderText findByPlaceholderText works 1`] = ` 162 | 165 | `; 166 | 167 | exports[`ReactTestingLibrary ByPlaceholderText getAllByPlaceholderText works 1`] = ` 168 | Array [ 169 | , 172 | ] 173 | `; 174 | 175 | exports[`ReactTestingLibrary ByPlaceholderText getByPlaceholderText works 1`] = ` 176 | 179 | `; 180 | 181 | exports[`ReactTestingLibrary ByPlaceholderText queryAllByPlaceholderText works 1`] = ` 182 | Array [ 183 | , 186 | ] 187 | `; 188 | 189 | exports[`ReactTestingLibrary ByPlaceholderText queryByPlaceholderText works (element not found) 1`] = `null`; 190 | 191 | exports[`ReactTestingLibrary ByPlaceholderText queryByPlaceholderText works 1`] = ` 192 | 195 | `; 196 | 197 | exports[`ReactTestingLibrary ByRole findAllByRole works 1`] = ` 198 | Array [ 199 | , 202 | ] 203 | `; 204 | 205 | exports[`ReactTestingLibrary ByRole findByRole works 1`] = ` 206 | 209 | `; 210 | 211 | exports[`ReactTestingLibrary ByRole getAllByRole works 1`] = ` 212 | Array [ 213 | , 216 | ] 217 | `; 218 | 219 | exports[`ReactTestingLibrary ByRole getByRole works 1`] = ` 220 | 223 | `; 224 | 225 | exports[`ReactTestingLibrary ByRole queryAllByRole works 1`] = ` 226 | Array [ 227 | , 230 | ] 231 | `; 232 | 233 | exports[`ReactTestingLibrary ByRole queryByRole works (element not found) 1`] = `null`; 234 | 235 | exports[`ReactTestingLibrary ByRole queryByRole works 1`] = ` 236 | 239 | `; 240 | 241 | exports[`ReactTestingLibrary ByTestId findAllByTestId works 1`] = ` 242 | Array [ 243 |

246 | Heading 247 |

, 248 | ] 249 | `; 250 | 251 | exports[`ReactTestingLibrary ByTestId findByTestId works 1`] = ` 252 |

255 | Heading 256 |

257 | `; 258 | 259 | exports[`ReactTestingLibrary ByTestId getAllByTestId works 1`] = ` 260 | Array [ 261 |

264 | Heading 265 |

, 266 | ] 267 | `; 268 | 269 | exports[`ReactTestingLibrary ByTestId getByTestId works 1`] = ` 270 |

273 | Heading 274 |

275 | `; 276 | 277 | exports[`ReactTestingLibrary ByTestId queryAllByTestId works 1`] = ` 278 | Array [ 279 |

282 | Heading 283 |

, 284 | ] 285 | `; 286 | 287 | exports[`ReactTestingLibrary ByTestId queryByTestId works (element not found) 1`] = `null`; 288 | 289 | exports[`ReactTestingLibrary ByTestId queryByTestId works 1`] = ` 290 |

293 | Heading 294 |

295 | `; 296 | 297 | exports[`ReactTestingLibrary ByText findAllByText works 1`] = ` 298 | Array [ 299 | 302 | About ℹ️ 303 | , 304 | ] 305 | `; 306 | 307 | exports[`ReactTestingLibrary ByText findByText works 1`] = ` 308 | 311 | About ℹ️ 312 | 313 | `; 314 | 315 | exports[`ReactTestingLibrary ByText getAllByText works 1`] = ` 316 | Array [ 317 | 320 | About ℹ️ 321 | , 322 | ] 323 | `; 324 | 325 | exports[`ReactTestingLibrary ByText getByText works 1`] = ` 326 | 329 | About ℹ️ 330 | 331 | `; 332 | 333 | exports[`ReactTestingLibrary ByText queryAllByText works 1`] = ` 334 | Array [ 335 | 338 | About ℹ️ 339 | , 340 | ] 341 | `; 342 | 343 | exports[`ReactTestingLibrary ByText queryByText works (element not found) 1`] = `null`; 344 | 345 | exports[`ReactTestingLibrary ByText queryByText works 1`] = ` 346 | 349 | About ℹ️ 350 | 351 | `; 352 | 353 | exports[`ReactTestingLibrary ByTitle findAllByTitle works 1`] = ` 354 | Array [ 355 | , 359 | ] 360 | `; 361 | 362 | exports[`ReactTestingLibrary ByTitle findByTitle works 1`] = ` 363 | 367 | `; 368 | 369 | exports[`ReactTestingLibrary ByTitle getAllByTitle works 1`] = ` 370 | Array [ 371 | , 375 | ] 376 | `; 377 | 378 | exports[`ReactTestingLibrary ByTitle getByTitle works 1`] = ` 379 | 383 | `; 384 | 385 | exports[`ReactTestingLibrary ByTitle queryAllByTitle works 1`] = ` 386 | Array [ 387 | , 391 | ] 392 | `; 393 | 394 | exports[`ReactTestingLibrary ByTitle queryByTitle works (element not found) 1`] = `null`; 395 | 396 | exports[`ReactTestingLibrary ByTitle queryByTitle works 1`] = ` 397 | 401 | `; 402 | 403 | exports[`ReactTestingLibrary Cleaunp, (element not found) 1`] = `null`; 404 | 405 | exports[`ReactTestingLibrary act works 1`] = ` 406 |
407 | Count: 1 408 | 411 | 414 |
415 | `; 416 | 417 | exports[`ReactTestingLibrary asFragment works 1`] = ` 418 | 419 |
422 |

425 | Heading 426 |

427 |
428 |
429 | `; 430 | 431 | exports[`ReactTestingLibrary render works 1`] = ` 432 | Object { 433 | "asFragment": [Function], 434 | "baseElement": 435 |
436 |
439 |

442 | Heading 443 |

444 |
445 |
446 | , 447 | "container":
448 |
451 |

454 | Heading 455 |

456 |
457 |
, 458 | "debug": [Function], 459 | "findAllByAltText": [Function], 460 | "findAllByDisplayValue": [Function], 461 | "findAllByLabelText": [Function], 462 | "findAllByPlaceholderText": [Function], 463 | "findAllByRole": [Function], 464 | "findAllByTestId": [Function], 465 | "findAllByText": [Function], 466 | "findAllByTitle": [Function], 467 | "findByAltText": [Function], 468 | "findByDisplayValue": [Function], 469 | "findByLabelText": [Function], 470 | "findByPlaceholderText": [Function], 471 | "findByRole": [Function], 472 | "findByTestId": [Function], 473 | "findByText": [Function], 474 | "findByTitle": [Function], 475 | "getAllByAltText": [Function], 476 | "getAllByDisplayValue": [Function], 477 | "getAllByLabelText": [Function], 478 | "getAllByPlaceholderText": [Function], 479 | "getAllByRole": [Function], 480 | "getAllByTestId": [Function], 481 | "getAllByText": [Function], 482 | "getAllByTitle": [Function], 483 | "getByAltText": [Function], 484 | "getByDisplayValue": [Function], 485 | "getByLabelText": [Function], 486 | "getByPlaceholderText": [Function], 487 | "getByRole": [Function], 488 | "getByTestId": [Function], 489 | "getByText": [Function], 490 | "getByTitle": [Function], 491 | "queryAllByAltText": [Function], 492 | "queryAllByDisplayValue": [Function], 493 | "queryAllByLabelText": [Function], 494 | "queryAllByPlaceholderText": [Function], 495 | "queryAllByRole": [Function], 496 | "queryAllByTestId": [Function], 497 | "queryAllByText": [Function], 498 | "queryAllByTitle": [Function], 499 | "queryByAltText": [Function], 500 | "queryByDisplayValue": [Function], 501 | "queryByLabelText": [Function], 502 | "queryByPlaceholderText": [Function], 503 | "queryByRole": [Function], 504 | "queryByTestId": [Function], 505 | "queryByText": [Function], 506 | "queryByTitle": [Function], 507 | "rerender": [Function], 508 | "unmount": [Function], 509 | } 510 | `; 511 | --------------------------------------------------------------------------------