Skip to content

Commit

Permalink
Extract half-generated "API.md" from README and JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Oct 8, 2017
1 parent ea2b67b commit 4733b46
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 51 deletions.
122 changes: 122 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# API

[htmlelement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement

[nodelist]: https://developer.mozilla.org/en-US/docs/Web/API/NodeList

## assert.dom()

Once installed the DOM element assertions are available at `assert.dom(...).*`:

**Parameters**

- `target` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element))** A CSS selector that can be used to find elements using [`querySelector()`](https://developer.mozilla.org/de/docs/Web/API/Document/querySelector), or an [HTMLElement][] (Not all assertions support both target types.)
- `rootElement` **[HTMLElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element)?** The root element of the DOM in which to search for the `target` (optional, default `document`)

**Examples**

```javascript
test('the title exists', function(assert) {
assert.dom('#title').exists();
});
```

## Assertions

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### exists

Assert an [HTMLElement][] (or multiple) matching the `selector` exists.

**Parameters**

- `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('#title').exists();
assert.dom('.choice').exists({ count: 4 });
```

### missing

Assert an [HTMLElement][] matching the `selector` does not exists.

**Parameters**

- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('.should-not-exist').missing();
```

### focused

Assert that the [HTMLElement][] or an [HTMLElement][] matching the
`selector` is currently focused.

**Parameters**

- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('input.email').focused();
```

### notFocused

Assert that the [HTMLElement][] or an [HTMLElement][] matching the
`selector` is not currently focused.

**Parameters**

- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('input[type="password"]').notFocused();
```

### textContains

Assert that the text of the [HTMLElement][] or an [HTMLElement][]
matching the `selector` contains the given `text`, using the
[`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent)
attribute.

**Parameters**

- `text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('#title').textContains('Welcome');
```

### textMatches

Assert that the text of the [HTMLElement][] or an [HTMLElement][]
matching the `selector` matches the given regular expression, using the
[`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent)
attribute.

**Parameters**

- `regex` **[RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)**
- `message` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

**Examples**

```javascript
assert.dom('.foo').textMatches(/[12]\d{3}/);
```
52 changes: 1 addition & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,7 @@ test('the title is friendly', function(assert) {
});
```


Assertions
------------------------------------------------------------------------------

### `assert.dom(selector).exists([options], [message])`
### `assert.dom(selector).missing([message])`

Assert an [HTMLElement][] (or multiple) matching the `selector` exists.

```js
assert.dom('#title').exists();
assert.dom('.choice').exists({ count: 4 });
assert.dom('.should-not-exist').missing();
```


### `assert.dom(selector|element).focused([message])`
### `assert.dom(selector|element).notFocused([message])`

Assert that the [HTMLElement][] is or is not currently focused.

```js
assert.dom('input.email').focused();
assert.dom(document.querySelector('input[type="password"]')).notFocused();
```


### `assert.dom(selector|element).textContains(text, [message])`

Assert that the text of the [HTMLElement][] contains the given `text`, using
[`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent).

```js
assert.dom('#title').textContains('Welcome');
assert.dom(document.querySelector('#title')).textContains('Welcome');
```


### `assert.dom(selector|element).textMatches(regex, [message])`

Assert that the text of the [HTMLElement][] matches the given regular expression, using
[`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent).

```js
assert.dom('.foo').textMatches(/[12]\d{3}/);
assert.dom(document.querySelector('.foo')).textMatches(/[12]\d{3}/);
```


[HTMLElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
[NodeList]: https://developer.mozilla.org/en-US/docs/Web/API/NodeList
**All available assertions are documented in [API.md](API.md).**


Related
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"repository": "https://github.com/simplabs/qunit-dom",
"scripts": {
"build": "rollup -c",
"docs": "documentation readme lib/qunit-dom.js --readme-file=API.md --section=Assertions",
"prepublish": "rollup -c",
"test": "jest",
"test:coverage": "jest --coverage",
Expand Down

0 comments on commit 4733b46

Please sign in to comment.