Skip to content

Commit 7dd8119

Browse files
committed
Initial commit
0 parents  commit 7dd8119

14 files changed

+4200
-0
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.js text eol=lf
3+
*.re linguist-language=OCaml

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Build
5+
coverage
6+
src/**/*.bs.js
7+
lib
8+
.bsb.lock
9+
.merlin
10+
11+
# Logs
12+
*.log
13+
14+
# macOS
15+
.*DS_Store

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sudo: false
2+
3+
language: node_js
4+
5+
node_js:
6+
- 10
7+
- 8
8+
9+
before_install:
10+
- curl -o- -L https://yarnpkg.com/install.sh | bash
11+
- export PATH="$HOME/.yarn/bin:$PATH"
12+
13+
cache:
14+
yarn: true
15+
directories:
16+
- $HOME/.cache
17+
- node_modules

bsconfig.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "bs-react-testing-library",
3+
"bsc-flags": [
4+
"-bs-no-version-header",
5+
"-bs-super-errors"
6+
],
7+
"reason": {
8+
"react-jsx": 2
9+
},
10+
"refmt": 3,
11+
"package-specs": {
12+
"module": "commonjs",
13+
"in-source": true
14+
},
15+
"suffix": ".bs.js",
16+
"bs-dependencies": [
17+
"bs-dom-testing-library",
18+
"reason-react"
19+
],
20+
"bs-dev-dependencies": [
21+
"bs-jest"
22+
],
23+
"sources": [
24+
{
25+
"dir": "src",
26+
"subdirs": [
27+
{
28+
"dir": "__tests__",
29+
"type": "dev"
30+
}
31+
]
32+
}
33+
]
34+
}

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Change Log

license

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Neil Kistner <[email protected]> (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.

package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "bs-react-testing-library",
3+
"version": "0.0.0",
4+
"description": "BuckleScript bindings for react-testing-library.",
5+
"repository": "wyze/bs-react-testing-library",
6+
"author": {
7+
"name": "Neil Kistner",
8+
"email": "[email protected]",
9+
"url": "neilkistner.com"
10+
},
11+
"license": "MIT",
12+
"files": [
13+
"src/*.re",
14+
"src/*.rei",
15+
"bsconfig.json"
16+
],
17+
"scripts": {
18+
"build": "bsb -make-world",
19+
"clean": "run-p clean:*",
20+
"clean:bsb": "bsb -clean-world",
21+
"clean:project": "rimraf lib .merlin",
22+
"jest": "jest",
23+
"prebuild": "yarn clean",
24+
"pretest": "yarn build",
25+
"test": "yarn jest",
26+
"version": "write-changelog"
27+
},
28+
"keywords": [
29+
"bucklescript",
30+
"testing"
31+
],
32+
"dependencies": {
33+
"bs-dom-testing-library": "^0.1.0",
34+
"react-testing-library": "^3.1.3"
35+
},
36+
"peerDependencies": {
37+
"reason-react": "^0.4.0 || ^0.3.0"
38+
},
39+
"devDependencies": {
40+
"bs-jest": "^0.3.2",
41+
"bs-platform": "^3.1.5",
42+
"npm-run-all": "^4.1.3",
43+
"react": "^16.4.0",
44+
"react-dom": "^16.4.0",
45+
"reason-react": "^0.4.2",
46+
"rimraf": "^2.6.2",
47+
"write-changelog": "^1.1.0"
48+
}
49+
}

readme.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# bs-react-testing-library
2+
3+
[![Build Status][travis-image]][travis-url]
4+
[![npm][npm-image]][npm-url]
5+
6+
> [BuckleScript](//github.com/BuckleScript/bucklescript) bindings for [react-testing-library](//github.com/kentcdodds/react-testing-library).
7+
8+
## Installation
9+
10+
```sh
11+
$ yarn add --dev bs-react-testing-library
12+
13+
# or..
14+
15+
$ npm install --save-dev bs-react-testing-library
16+
```
17+
18+
## Usage
19+
20+
#### Add to `bsconfig.json`
21+
22+
```json
23+
{
24+
"bs-dev-dependencies": [
25+
"bs-react-testing-library"
26+
]
27+
}
28+
```
29+
30+
#### With [`bs-jest`](//github.com/reasonml-community/bs-jest)
31+
32+
```ocaml
33+
/* Component_test.re */
34+
35+
open Jest;
36+
37+
describe("Component", () => {
38+
open ExpectJs;
39+
40+
test("renders", () => {
41+
let component = ReactShallowRenderer.renderWithRenderer(<Component />);
42+
43+
expect(Js.Undefined.return(component)) |> toBeDefined;
44+
});
45+
});
46+
```
47+
48+
## Examples
49+
50+
See [`src/__tests__`](src/__tests__) for some examples.
51+
52+
## Development
53+
54+
```sh
55+
$ git clone https://github.com/wyze/bs-react-testing-library.git
56+
$ cd bs-react-testing-library
57+
$ yarn # or `npm install`
58+
```
59+
60+
## Build
61+
62+
```sh
63+
$ yarn build
64+
```
65+
66+
## Test
67+
68+
```sh
69+
$ yarn test
70+
```
71+
72+
## Change Log
73+
74+
> [Full Change Log](changelog.md)
75+
76+
## License
77+
78+
MIT © [Neil Kistner](https://neilkistner.com)
79+
80+
[travis-image]: https://img.shields.io/travis/wyze/bs-react-testing-library.svg?style=flat-square
81+
[travis-url]: https://travis-ci.org/wyze/bs-react-testing-library
82+
83+
[npm-image]: https://img.shields.io/npm/v/bs-react-testing-library.svg?style=flat-square
84+
[npm-url]: https://npm.im/bs-react-testing-library

src/ReactTestingLibrary.re

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
include DomTestingLibrary;
2+
3+
module Simulate = {
4+
[@bs.module "react-testing-library"] [@bs.scope "Simulate"]
5+
external click : Dom.element => unit = "";
6+
};
7+
8+
type renderResult;
9+
type renderOptions = {
10+
.
11+
"container": Js.undefined(Dom.element),
12+
};
13+
14+
[@bs.module "react-testing-library"]
15+
external cleanup : unit => unit = "";
16+
17+
[@bs.module "react-testing-library"]
18+
external renderIntoDocument : ReasonReact.reactElement => renderResult = "";
19+
20+
[@bs.module "react-testing-library"]
21+
external _render : (ReasonReact.reactElement, renderOptions) => renderResult = "render";
22+
23+
[@bs.get] external container : renderResult => Dom.element = "";
24+
25+
[@bs.send.pipe : renderResult] external debug : unit = "";
26+
27+
[@bs.send.pipe : renderResult] external unmount : unit => bool = "";
28+
29+
[@bs.send.pipe : renderResult] external rerender : ReasonReact.reactElement => unit = "";
30+
31+
let render = (~container=?, element) =>
32+
_render(element, { "container": Js.Undefined.fromOption(container) });
33+

src/ReactTestingLibrary.rei

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module Query = DomTestingLibrary.Query;
2+
module Wait = DomTestingLibrary.Wait;
3+
module WaitForElement = DomTestingLibrary.WaitForElement;
4+
5+
let wait:
6+
(~callback: unit => unit=?, ~options: Wait.options=?, unit) =>
7+
Js.Promise.t('a);
8+
9+
let waitForElement:
10+
(~callback: unit => 'a=?, ~options: WaitForElement.options=?, unit) =>
11+
Js.Promise.t('a);
12+
13+
let prettyDOM: (~maxLength: int=?, Dom.element) => string;
14+
15+
[@bs.module "dom-testing-library"]
16+
external getNodeText : Dom.element => string = "";
17+
18+
let getByTestId: (string, Dom.element) => Dom.element;
19+
20+
let getByText:
21+
(
22+
~matcher: [
23+
| `Func((string, Dom.element) => bool)
24+
| `RegExp(Js.Re.t)
25+
| `Str(string)
26+
],
27+
~options: Query.options=?,
28+
Dom.element
29+
) =>
30+
Dom.element;
31+
32+
module Simulate: {
33+
[@bs.module "react-testing-library"] [@bs.scope "Simulate"]
34+
external click : Dom.element => unit = "";
35+
};
36+
37+
type renderResult;
38+
type renderOptions = {. "container": Js.undefined(Dom.element)};
39+
40+
[@bs.module "react-testing-library"]
41+
external cleanup : unit => unit = "";
42+
43+
[@bs.module "react-testing-library"]
44+
external renderIntoDocument : ReasonReact.reactElement => renderResult = "";
45+
46+
[@bs.get]
47+
external container : renderResult => Dom.element = "";
48+
49+
[@bs.send.pipe : renderResult]
50+
external debug : unit = "";
51+
52+
[@bs.send.pipe : renderResult]
53+
external unmount : unit => bool = "";
54+
55+
[@bs.send.pipe : renderResult]
56+
external rerender : ReasonReact.reactElement => unit = "";
57+
58+
let render:
59+
(~container: Dom.element=?, ReasonReact.reactElement) => renderResult;

0 commit comments

Comments
 (0)