Skip to content

Commit

Permalink
docs: Improve fixture docs #563
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiuch committed Feb 16, 2018
1 parent 88d0020 commit a3d525e
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Jump to:
* [Children](#children)
* [State](#state)
* [Init hook](#init-hook)
* [Fixture name and namespace](#fixture-name-and-namespace)
* [Proxies](#proxies)
* [What's a proxy?](#whats-a-proxy)
* [Where to put proxies?](#where-to-put-proxies)
Expand Down Expand Up @@ -172,6 +173,27 @@ export default {

Cosmos looks for `*.fixture` named files and files inside `__fixtures__` dirs by default. See [custom fixture paths](#custom-fixture-paths) for further customization.

It is also possible to export an array of fixtures from a single file. You may want to define the [fixture name and namespace](#fixture-name-and-namespace) in this case.

```js
export default [
{
component: Input,
name: 'disabled',
props: {
disabled: true
}
},
{
component: Input,
name: 'enabled',
props: {
disabled: false
}
}
];
```

#### Props

Mocking props is the most basic thing a fixture can do.
Expand Down Expand Up @@ -233,35 +255,16 @@ export default {
};
```

#### Other fixture Properties

```
{
name: // string - specify a title for the fixture. Otherwise it will default to the relevant component name
namespace: // string - allows nesting of fixtures which share the same namespace
}
```
#### Fixture name and namespace

It is also possible to export an array of fixtures from a single file. The above properties can be particularly useful in this case. For example
The fixture name and namespace are detected automatically from the file name and file path respectively, but they can be overridden with custom values.

```js
export default [{
component: SearchBox,
namespace: 'Searching for pets',
name: 'Dog search',
state: {
searchQuery: 'Who let the dogs out?'
}
},
{
export default {
component: SearchBox,
namespace: 'Searching for pets',
name: 'Dog search',
state: {
searchQuery: 'où est le chat?'
}
}]
name: 'dog search',
namespace: 'dashboard/pets'
};
```

### Proxies
Expand Down

0 comments on commit a3d525e

Please sign in to comment.