Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging helper to add arguments passed to functions #16

Closed
NicholasBoll opened this issue Apr 24, 2019 · 0 comments · Fixed by #17
Closed

Add logging helper to add arguments passed to functions #16

NicholasBoll opened this issue Apr 24, 2019 · 0 comments · Fixed by #17

Comments

@NicholasBoll
Copy link
Owner

NicholasBoll commented Apr 24, 2019

pipe is useful to tell us what functions are passed to pipe, but if those functions take parameters, those arguments are completely invisible.

Example:

const getTodoByName = (name) => function getTodoByName($list) {
  return $list.find(`.todo-item:contains(${name})`)
}

cy.get('.todo-list')
  .pipe(getTodoByName('My Todo')
  .should('contain', 'My Todo')

Log shows:

GET        .todo-list
 - PIPE    getTodoByName
 - ASSERT  expected .todo-item to contain 'My Todo'

It should show:

GET        .todo-list
 - PIPE    getTodoByName 'My Todo'
 - ASSERT  expected .todo-item to contain 'My Todo'

It isn't possible for pipe through arguments, but a helper function could help out. Something like:

import { loggable } from 'cypress-pipe'

const getTodoByName = loggable((name) => function getTodoByName($list) {
  return $list.find(`.todo-item:contains(${name})`)
})
NicholasBoll added a commit that referenced this issue Apr 27, 2019
`loggable` attaches additional metadata to helper functions for the `.pipe` Command. This includes ensuring the display name of a function regardless of the function being anonymous and also attaches parameters passed.

Example:
```ts
const getProp = loggable('getProp', prop => obj => obj[prop]
cy.wrap({ foo: 'bar'  })
  .pipe(getProp('foo'))
  .should('equal', 'bar')
```

This will show the following in the the Cypress Command Log:
```
WRAP      {foo: bar}
- PIPE    getProp("foo")
- ASSERT  expected bar to equal bar
```

Without using `loggable`, the `PIPE` line would not include arguments passed to `getProp`:
```
- PIPE   getProp
```

Fixes #16
NicholasBoll added a commit that referenced this issue Apr 27, 2019
`loggable` attaches additional metadata to helper functions for the `.pipe` Command. This includes ensuring the display name of a function regardless of the function being anonymous and also attaches parameters passed.

Example:
```ts
const getProp = loggable('getProp', prop => obj => obj[prop]
cy.wrap({ foo: 'bar'  })
  .pipe(getProp('foo'))
  .should('equal', 'bar')
```

This will show the following in the the Cypress Command Log:
```
WRAP      {foo: bar}
- PIPE    getProp("foo")
- ASSERT  expected bar to equal bar
```

Without using `loggable`, the `PIPE` line would not include arguments passed to `getProp`:
```
- PIPE   getProp
```

Fixes #16
NicholasBoll added a commit that referenced this issue Apr 27, 2019
`loggable` attaches additional metadata to helper functions for the `.pipe` Command. This includes ensuring the display name of a function regardless of the function being anonymous and also attaches parameters passed.

Example:
```ts
const getProp = loggable('getProp', prop => obj => obj[prop]
cy.wrap({ foo: 'bar'  })
  .pipe(getProp('foo'))
  .should('equal', 'bar')
```

This will show the following in the the Cypress Command Log:
```
WRAP      {foo: bar}
- PIPE    getProp("foo")
- ASSERT  expected bar to equal bar
```

Without using `loggable`, the `PIPE` line would not include arguments passed to `getProp`:
```
- PIPE   getProp
```

Fixes #16
NicholasBoll added a commit that referenced this issue Apr 27, 2019
`loggable` attaches additional metadata to helper functions for the `.pipe` Command. This includes ensuring the display name of a function regardless of the function being anonymous and also attaches parameters passed.

Example:
```ts
const getProp = loggable('getProp', prop => obj => obj[prop]
cy.wrap({ foo: 'bar'  })
  .pipe(getProp('foo'))
  .should('equal', 'bar')
```

This will show the following in the the Cypress Command Log:
```
WRAP      {foo: bar}
- PIPE    getProp("foo")
- ASSERT  expected bar to equal bar
```

Without using `loggable`, the `PIPE` line would not include arguments passed to `getProp`:
```
- PIPE   getProp
```

Fixes #16
NicholasBoll added a commit that referenced this issue May 2, 2019
`loggable` attaches additional metadata to helper functions for the `.pipe` Command. This includes ensuring the display name of a function regardless of the function being anonymous and also attaches parameters passed.

Example:
```ts
const getProp = loggable('getProp', prop => obj => obj[prop]
cy.wrap({ foo: 'bar'  })
  .pipe(getProp('foo'))
  .should('equal', 'bar')
```

This will show the following in the the Cypress Command Log:
```
WRAP      {foo: bar}
- PIPE    getProp("foo")
- ASSERT  expected bar to equal bar
```

Without using `loggable`, the `PIPE` line would not include arguments passed to `getProp`:
```
- PIPE   getProp
```

Fixes #16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant