Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jahredhope/some-values
Create non-magical values for unit tests
https://github.com/jahredhope/some-values
npm-package
Last synced: about 1 month ago
JSON representation
Create non-magical values for unit tests
- Host: GitHub
- URL: https://github.com/jahredhope/some-values
- Owner: jahredhope
- Created: 2016-07-06T00:16:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-16T00:27:41.000Z (over 6 years ago)
- Last Synced: 2024-10-11T00:34:50.908Z (about 1 month ago)
- Topics: npm-package
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# some-values
## I don't believe in magic
I don't believe in magic numbers
I don't believe in magic stringsWhen writing tests we often specify values
```
api.save(5)
expect(api.validate).calledWith(5)
```
This reads like 5 is important, but what if 5 isn't important, we are simply saying 'given I save a number I get a number'. Enter `some-values`...
```
api.save(a.number)
expect(api.validate).calledWith(a.number)
```## Install
```
npm install --save-dev some-values
```## Use it
### Basic
```
someValues = require('some-values')a = someValues()
``````
a.string // Returns a random string
a.string // Returns the same stringa.number // Returns a random number
a.number // Returns the same number
```### Multiple
Need multiple values?
```
a = someValues()
b = someValues()a.string // Returns a random string
b.string // Returns another random string
a.string // Returns the first string
```## Supported Values
#### String
A random *Length* of *Char*
0 < *Length* < 20
*Char* = [a..b]#### Number
A random number of *Value*
0 < *Value* < 100#### Digit
A random number of *Value*
0 <= *Value* <= 9### Bring your own
```
a = someValues({
string: () => 'myOwnString'
reallyLongNumber: () => 1000 + Math.floor(Math.random()*1000)
})
```## What's on the horizon?
Add Date, ISO Datetime