Skip to content

Commit

Permalink
Added remaining tests to yank
Browse files Browse the repository at this point in the history
  • Loading branch information
marziply committed Jul 20, 2021
1 parent a939785 commit 7b7c82c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ thisWontBeInTheResult
}
```

##### Available filters
#### Available filters

| Name | Arguments | Macro | Description |
|:---|:---|:---|:---|
Expand Down Expand Up @@ -360,7 +360,7 @@ yank(data, [
## Tests

```sh
$ npm run test
$ npm test
```

## Acknowledgments
Expand Down
26 changes: 17 additions & 9 deletions tests/yank.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,56 @@ const data = require('./data')

describe('src/yank', () => {
it('should yank provided properties from a data object', () => {
const yanked = yank(data, 'firstName', 'lastName')
const result = yank(data, 'firstName', 'lastName')

expect(yanked).toEqual({
expect(result).toEqual({
firstName: 'John',
lastName: 'Doe'
})
})

it('should yank provided properties as an array from a data object', () => {
const yanked = yank(data, [
const result = yank(data, [
'firstName',
'lastName'
])

expect(yanked).toEqual({
expect(result).toEqual({
firstName: 'John',
lastName: 'Doe'
})
})

it('should ignore all properties that do not exist on the data object', () => {
const yanked = yank(data, 'emailAddress', 'firstName')
const result = yank(data, 'emailAddress', 'firstName')

expect(yanked.emailAddress).toBeUndefined()
expect(yanked).toEqual({
expect(result.emailAddress).toBeUndefined()
expect(result).toEqual({
firstName: 'John'
})
})

it('should return nested results', () => {
const yanked = yank(data, `
const result = yank(data, `
addressDetails: {
city,
postcode
}
`)

expect(yanked).toEqual({
expect(result).toEqual({
addressDetails: {
city: 'London',
postcode: 'SW1A 2AB'
}
})
})

it('should return properties via a property path', () => {
const result = yank(data, 'nested.data.items.one')

expect(result).toEqual({
one: 'one'
})
})
})

0 comments on commit 7b7c82c

Please sign in to comment.