all files / src/__tests__/ addExpectations.js

100% Statements 22/22
90% Branches 9/10
100% Functions 6/6
100% Lines 13/13
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29              530× 530× 20156× 19458×     530× 18036×   530× 2120×     530×          
import expect from 'expect'
 
/**
 * Takes expectations and extends expect with them. Cannot use expect.extends due to the
 * asynchronous nature of the tests.
 * @param expectations Expectations to add
 */
const addExpectations = expectations => {
  const decorate = dest => {
    Eif (dest) {
      const wrap = (value, key) => {
        if (typeof value === 'function' && key !== 'actual') {
          dest[ key ] = (...params) => decorate(value.apply(dest, params))
        }
      }
      for (let key in dest) {
        wrap(dest[ key ], key)
      }
      for (let key in expectations) {
        wrap(expectations[ key ], key)
      }
    }
    return dest
  }
  return (...params) => decorate(expect(...params))
}
 
export default addExpectations