|
1 | 1 | /// <reference types="cypress" /> |
2 | 2 | /// <reference path="../../index.d.ts" /> |
3 | 3 |
|
| 4 | +const { loggable } = require('../../loggable') |
| 5 | + |
4 | 6 | const delay = 100 // delay of some retries. Make this larger if you want to see the UI during these times |
5 | 7 |
|
| 8 | +describe('loggable', () => { |
| 9 | + context('when only a function is provided', () => { |
| 10 | + it('should set __args to equal arguments passed in', () => { |
| 11 | + const getProp = loggable(prop => obj => obj[prop]) |
| 12 | + const fn = getProp('foo', 1, false) |
| 13 | + expect(fn.__args).to.deep.equal(['foo', 1, false]) |
| 14 | + }) |
| 15 | + |
| 16 | + it('should set displayName to the name of the function', () => { |
| 17 | + const getFoo = loggable(function getFoo() {}) |
| 18 | + expect(getFoo.displayName).to.equal('getFoo') |
| 19 | + }) |
| 20 | + }) |
| 21 | + |
| 22 | + context('when a name is provided', () => { |
| 23 | + it('should set the displayName of the function', () => { |
| 24 | + const getFoo = loggable('getFoo', () => 'foo') |
| 25 | + console.log('getFoo', getFoo) |
| 26 | + expect(getFoo.displayName).to.equal('getFoo') |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + context('when a curried function is provided', () => { |
| 31 | + it('should set the displayName of the curried function', () => { |
| 32 | + const getFoo = loggable('getFoo', prop => obj => obj[prop]) |
| 33 | + const fn = getFoo('foo') |
| 34 | + expect(fn.displayName).to.equal('getFoo') |
| 35 | + }) |
| 36 | + }) |
| 37 | +}) |
| 38 | + |
6 | 39 | describe('pipe()', () => { |
7 | 40 |
|
8 | 41 | context('when passed a synchronous function', () => { |
@@ -31,6 +64,26 @@ describe('pipe()', () => { |
31 | 64 | .pipe(getFoo) |
32 | 65 | }) |
33 | 66 |
|
| 67 | + it('should show arguments of loggable functions', (done) => { |
| 68 | + const getProp = loggable('getProp', (prop) => (obj) => obj[prop]) |
| 69 | + const args = ['foo', 1, (foo) => foo, false, [1, 'foo'], { foo: 'bar' }] |
| 70 | + |
| 71 | + cy.on('log:changed', (attrs, log) => { |
| 72 | + if (log.get('name') === 'pipe') { |
| 73 | + cy.removeAllListeners('log:changed') |
| 74 | + |
| 75 | + expect(log.get('message')).to.eq('getProp("foo", 1, function, false, [1,"foo"], {"foo":"bar"})') |
| 76 | + expect(log.invoke('consoleProps')).to.have.property('Arguments') |
| 77 | + expect(log.invoke('consoleProps').Arguments).to.deep.equal(args) |
| 78 | + done() |
| 79 | + } |
| 80 | + }) |
| 81 | + |
| 82 | + cy.wrap({ foo: 'bar' }) |
| 83 | + .pipe(getProp(...args)) |
| 84 | + .should('equal', 'bar') |
| 85 | + }) |
| 86 | + |
34 | 87 | it('should retry until assertion passes', () => { |
35 | 88 | const obj = { foo: 'bar' } |
36 | 89 | setTimeout(() => { obj.foo = 'baz' }, delay) |
|
0 commit comments