Sha256: fe17de4e650320d7352af336edda8235e2ea8c2d1f78360cb1c3bc13ea9e16d6

Contents?: true

Size: 1011 Bytes

Versions: 76

Compression:

Stored size: 1011 Bytes

Contents

/* global test expect */

const deepAssign = require('../deep_assign')

describe('deepAssign()', () => {
  test('deeply assigns nested properties', () => {
    const object = { foo: { bar: { } } }
    const path = 'foo.bar'
    const value = { x: 1, y: 2 }
    const expectation = { foo: { bar: { x: 1, y: 2 } } }
    expect(deepAssign(object, path, value)).toEqual(expectation)
  })

  test('allows assignment of a literal false', () => {
    const object = { foo: { bar: { } } }
    const path = 'foo.bar'
    const value = false
    const expectation = { foo: { bar: false } }
    expect(deepAssign(object, path, value)).toEqual(expectation)
  })

  test('does not allow assignment of other falsy values', () => {
    const object = { foo: { bar: { } } }
    const path = 'foo.bar'
    const values = [undefined, null, 0, '']

    values.forEach(value => {
      const expectation = new Error(`Value can't be ${value}`)
      expect(() => deepAssign(object, path, value)).toThrow(expectation)
    })
  })
})

Version data entries

76 entries across 75 versions & 12 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/deep_assign.js
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/deep_assign.js
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/deep_assign.js
optimacms-0.1.61 spec/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
jetpacker-0.7.0 package/utils/__tests__/deep_assign.js
webpacker-5.4.4 package/utils/__tests__/deep_assign.js
jetpacker-0.6.0 package/utils/__tests__/deep_assign.js
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.16.1 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.15.2 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.18.4 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.18.1 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.14.0 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/deep_assign.js
webpacker-5.4.3 package/utils/__tests__/deep_assign.js
webpacker-5.4.2 package/utils/__tests__/deep_assign.js
webpacker-5.4.1 package/utils/__tests__/deep_assign.js
webpacker-5.4.0 package/utils/__tests__/deep_assign.js