Skip to content

Commit

Permalink
Add documentation for invar.req and invar.notEqual.
Browse files Browse the repository at this point in the history
  • Loading branch information
kern committed Mar 8, 2016
1 parent 840e62b commit a8e6c51
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import invar from 'invar'
```

---

### `invar(message)`

Check for truthiness.
Expand All @@ -28,6 +30,8 @@ invar(2 + 2 === 5, "I'm sorry Dave, I'm afraid I can't do that.")

Invariant Violation: I'm sorry Dave, I'm afraid I can't do that.

---

### `invar.equal(actual, expected, message)`

Check for shallow equality.
Expand All @@ -41,8 +45,45 @@ invar.equal(2 + 2, 5, "Daisy, Daisy, give me your answer do.")
#### Throws

Invariant Violation: Daisy, Daisy, give me your answer do.
Actual: 4
Expected: 5
actual: 4
expected: 5

---

### `invar.notEqual(actual, expected, message)`

Check for shallow unequality.

#### Example

```javascript
invar.notEqual(2 + 2, 4, "I've just picked up a fault in the AE35 unit.")
```

#### Throws

Invariant Violation: I've just picked up a fault in the AE35 unit.
actual: 4
expected: not 4

---

### `invar.req(arg)`

Always fail. Used for mandatory function arguments.

#### Example

```javascript
function myFunction (mandatoryArg = invar.req('mandatoryArg')) {}
myFunction()
```

#### Throws

Invariant Violation: Required argument 'mandatoryArg' not provided.

---

### `invar.fail(message)`

Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('invar.fail', () => {
describe('invar.req', () => {
it('throws a generic error when no argument name is provided', () => {
try {
invar.req()
function fn (daisy = invar.req()) {}
fn()
expect(false).toBeTruthy()
} catch (ex) {
expect(ex.name).toBe('Invariant Violation')
Expand All @@ -44,7 +45,8 @@ describe('invar.req', () => {

it('throws a specific error when an argument name is provided', () => {
try {
invar.req('daisy')
function fn (daisy = invar.req('daisy')) {}
fn()
expect(false).toBeTruthy()
} catch (ex) {
expect(ex.name).toBe('Invariant Violation')
Expand Down

0 comments on commit a8e6c51

Please sign in to comment.