File: shallowEqual.spec.ts

package info (click to toggle)
node-react-redux 8.1.2%2Bdfsg1%2B~cs1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,820 kB
  • sloc: javascript: 1,214; makefile: 21
file content (80 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import shallowEqual from '../../src/utils/shallowEqual'

describe('Utils', () => {
  describe('shallowEqual', () => {
    it('should return true if arguments fields are equal', () => {
      expect(
        shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined })
      ).toBe(true)

      expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(
        true
      )

      const o = {}
      expect(shallowEqual({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe(
        true
      )

      const d = function () {
        return 1
      }
      expect(
        shallowEqual({ a: 1, b: 2, c: o, d }, { a: 1, b: 2, c: o, d })
      ).toBe(true)
    })

    it('should return false if arguments fields are different function identities', () => {
      expect(
        shallowEqual(
          {
            a: 1,
            b: 2,
            d: function () {
              return 1
            },
          },
          {
            a: 1,
            b: 2,
            d: function () {
              return 1
            },
          }
        )
      ).toBe(false)
    })

    it('should return false if first argument has too many keys', () => {
      expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false)
    })

    it('should return false if second argument has too many keys', () => {
      expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false)
    })

    it('should return false if arguments have different keys', () => {
      expect(
        shallowEqual(
          { a: 1, b: 2, c: undefined },
          { a: 1, bb: 2, c: undefined }
        )
      ).toBe(false)
    })

    it('should compare two NaN values', () => {
      expect(shallowEqual(NaN, NaN)).toBe(true)
    })

    it('should compare empty objects, with false', () => {
      expect(shallowEqual({}, false)).toBe(false)
      expect(shallowEqual(false, {})).toBe(false)
      expect(shallowEqual([], false)).toBe(false)
      expect(shallowEqual(false, [])).toBe(false)
    })

    it('should compare two zero values', () => {
      expect(shallowEqual(0, 0)).toBe(true)
    })
  })
})