Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Sep 18, 2018
0 parents commit d1575b8
Show file tree
Hide file tree
Showing 13 changed files with 4,622 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.js text eol=lf
*.re linguist-language=OCaml
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dependencies
coverage
node_modules

# Build
src/**/*.bs.js
lib
.bsb.lock
.merlin
extend-expect.js

# Logs
*.log

# macOS
.*DS_Store
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false

language: node_js

node_js: 8

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"

cache:
yarn: true
directories:
- $HOME/.cache
- node_modules

jobs:
include:
- stage: test
script: yarn test --maxWorkers=2
- stage: test
node_js: 10
script: yarn test --maxWorkers=2
- stage: code coverage
install: yarn add --dev coveralls
script: yarn test --maxWorkers=2 --coverage --coverageReporters=text-lcov | coveralls
30 changes: 30 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "bs-jest-dom",
"bsc-flags": [
"-bs-no-version-header",
"-bs-super-errors"
],
"reason": {
"react-jsx": 2
},
"refmt": 3,
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"sources": [
{
"dir": "src",
"subdirs": [
{
"dir": "__tests__",
"type": "dev"
}
]
}
],
"bs-dependencies": [
"@glennsl/bs-jest"
]
}
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Change Log
9 changes: 9 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) Neil Kistner <neil.kistner@gmail.com> (neilkistner.com)

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "bs-jest-dom",
"version": "0.0.0",
"description": "BuckleScript bindings for jest-dom.",
"repository": "wyze/bs-jest-dom",
"author": {
"name": "Neil Kistner",
"email": "neil.kistner@gmail.com",
"url": "neilkistner.com"
},
"license": "MIT",
"files": [
"src/*.re",
"src/*.rei",
"bsconfig.json"
],
"scripts": {
"build": "bsb -make-world",
"clean": "run-p clean:*",
"clean:bsb": "bsb -clean-world",
"clean:project": "rimraf lib .merlin",
"jest": "jest",
"prebuild": "yarn clean",
"pretest": "yarn build",
"preversion": "yarn build",
"test": "yarn jest",
"version": "write-changelog"
},
"keywords": [
"bucklescript",
"testing",
"jest",
"dom"
],
"dependencies": {
"@glennsl/bs-jest": "^0.4.4",
"jest-dom": "^1.12.0"
},
"devDependencies": {
"bs-platform": "^4.0.5",
"npm-run-all": "^4.1.3",
"rimraf": "^2.6.2",
"write-changelog": "^1.2.0"
}
}
98 changes: 98 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# bs-jest-dom

[![Build Status][travis-image]][travis-url]
[![npm][npm-image]][npm-url]
[![Coveralls][coveralls-image]][coveralls-url]

> [BuckleScript](//github.com/BuckleScript/bucklescript) bindings for [jest-dom](//github.com/gnapse/jest-dom).
## Installation

```sh
$ yarn add --dev bs-jest-dom

# or..

$ npm install --save-dev bs-jest-dom
```

## Usage

#### Add to `bsconfig.json`

```json
{
"bs-dev-dependencies": [
"bs-jest-dom"
]
}
```

#### With [`bs-jest`](//github.com/glennsl/bs-jest) and [`bs-react-testing-library`](//github.com/wyze/bs-react-testing-library)

```ocaml
/* A_test.re */
open Jest;
open JestDom;
open ReactTestingLibrary;
module Heading = {
let component = ReasonReact.statelessComponent("Heading");
let make = (~text, _children) => {
...component,
render: _self =>
<h1> {ReasonReact.string(text)} </h1>,
};
};
test("renders with text", () =>
<Heading text="Hello, World!" />
|> render
|> getByText(~matcher=`Str("Hello, World!"))
|> expect
|> toBeInTheDocument
);
```

## Examples

See [`src/__tests__`](src/__tests__) for some examples.

## Development

```sh
$ git clone https://github.com/wyze/bs-jest-dom.git
$ cd bs-jest-dom
$ yarn # or `npm install`
```

## Build

```sh
$ yarn build
```

## Test

```sh
$ yarn test
```

## Change Log

> [Full Change Log](changelog.md)
## License

MIT © [Neil Kistner](https://neilkistner.com)

[travis-image]: https://img.shields.io/travis/wyze/bs-jest-dom.svg?style=flat-square
[travis-url]: https://travis-ci.org/wyze/bs-jest-dom

[npm-image]: https://img.shields.io/npm/v/bs-jest-dom.svg?style=flat-square
[npm-url]: https://npm.im/bs-jest-dom

[coveralls-image]: https://img.shields.io/coveralls/github/wyze/bs-jest-dom.svg?style=flat-square
[coveralls-url]: https://coveralls.io/github/wyze/bs-jest-dom
73 changes: 73 additions & 0 deletions src/JestDom.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Bring in all of the matchers. */
[%bs.raw {|require('jest-dom/extend-expect')|}];

type ex;
[@bs.val] external expect: Dom.element => ex = "";

[@bs.get] external not_: ex => ex = "not";

[@bs.send.pipe: ex] external toBeDisabled_: unit = "toBeDisabled";

[@bs.send.pipe: ex] external toBeEmpty_: unit = "toBeEmpty";

[@bs.send.pipe: ex] external toBeInTheDocument_: unit = "toBeInTheDocument";

[@bs.send.pipe: ex] external toBeVisible_: unit = "toBeVisible";

[@bs.send.pipe: ex]
external toContainElement_: Js.Nullable.t(Dom.element) => unit =
"toContainElement";

[@bs.send.pipe: ex] external toContainHTML_: string => unit = "toContainHTML";

[@bs.send.pipe: ex]
external toHaveAttribute_: string => unit = "toHaveAttribute";

[@bs.send.pipe: ex]
external toHaveAttributeWithValue_: (string, string) => unit =
"toHaveAttribute";

[@bs.send.pipe: ex] external toHaveClass_: string => unit = "toHaveClass";

[@bs.send.pipe: ex]
external toHaveClass2_: (string, string) => unit = "toHaveClass";

[@bs.send.pipe: ex] external toHaveFocus_: unit = "toHaveFocus";

[@bs.send.pipe: ex] external toHaveStyle_: string => unit = "toHaveStyle";

[@bs.send.pipe: ex]
external toHaveTextContent_:
([@bs.unwrap] [ | `Str(string) | `RegExp(Js.Re.t)]) => unit =
"toHaveTextContent";

let pass = _ => Jest.pass;

let toBeDisabled = ex => ex |> toBeDisabled_ |> pass;

let toBeEmpty = ex => ex |> toBeEmpty_ |> pass;

let toBeInTheDocument = ex => ex |> toBeInTheDocument_ |> pass;

let toBeVisible = ex => ex |> toBeVisible_ |> pass;

let toContainElement = (ex, el) => ex |> toContainElement_(el) |> pass;

let toContainHTML = (ex, html) => ex |> toContainHTML_(html) |> pass;

let toHaveAttribute = (ex, attribute) =>
ex |> toHaveAttribute_(attribute) |> pass;

let toHaveAttributeWithValue = (ex, attribute, value) =>
ex |> toHaveAttributeWithValue_(attribute, value) |> pass;

let toHaveClass = (ex, value) => ex |> toHaveClass_(value) |> pass;

let toHaveClass2 = (ex, value1, value2) =>
ex |> toHaveClass2_(value1, value2) |> pass;

let toHaveFocus = ex => ex |> toHaveFocus_ |> pass;

let toHaveStyle = (ex, style) => ex |> toHaveStyle_(style) |> pass;

let toHaveTextContent = (ex, text) => ex |> toHaveTextContent_(text) |> pass;
18 changes: 18 additions & 0 deletions src/JestDom.rei
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type ex;
[@bs.val] external expect: Dom.element => ex = "";
[@bs.get] external not_: ex => ex = "not";

let toBeDisabled: ex => Jest.assertion;
let toBeEmpty: ex => Jest.assertion;
let toBeInTheDocument: ex => Jest.assertion;
let toBeVisible: ex => Jest.assertion;
let toContainElement: (ex, Js.Nullable.t(Dom.element)) => Jest.assertion;
let toContainHTML: (ex, string) => Jest.assertion;
let toHaveAttribute: (ex, string) => Jest.assertion;
let toHaveAttributeWithValue: (ex, string, string) => Jest.assertion;
let toHaveClass: (ex, string) => Jest.assertion;
let toHaveClass2: (ex, string, string) => Jest.assertion;
let toHaveFocus: ex => Jest.assertion;
let toHaveStyle: (ex, string) => Jest.assertion;
let toHaveTextContent:
(ex, [ `RegExp(Js.Re.t) | `Str(string) ]) => Jest.assertion;
Loading

0 comments on commit d1575b8

Please sign in to comment.