all files / src/structure/plain/ expectations.js

89.47% Statements 17/19
90.48% Branches 19/21
87.5% Functions 7/8
80% Lines 8/10
1 statement, 1 function, 7 branches 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 30 31 32 33 34 35 36 37 38 39 40                                                        52×          
import expect from 'expect'
 
const isObject = value => value && typeof value === 'object'
 
const expectations = {
  toBeAList() {
    expect.assert(
      Array.isArray(this.actual),
      'expected %s to be an array',
      this.actual
    )
    return this
  },
 
  toBeAMap() {
    expect.assert(
      isObject(this.actual),
      'expected %s to be an object',
      this.actual
    )
    return this
  },
 
  toBeSize(size) {
    expect.assert(
      this.actual && (Array.isArray(this.actual) ? this.actual : Object.keys(this.actual)).length === size,
      'expected %s to contain %s elements',
      this.actual,
      size
    )
    return this
  },
 
  toEqualMap(expected) {
    return expect(this.actual).toEqual(expected)
  }
}
 
export default expectations