Skip to content

Test cases to add. Mutating a reactive parent. #2

Open
@Lee182

Description

@Lee182

Just added these test cases for when mutating a reactive parent. I ran into the second issue realising the ref which I created had been overwritten. Don't know if this warning should be added to the docs which "watchers to refs that have been overwritten at the parent level will not fire".

test('should work with mutating parent', (assert) => {
  let state = reactive({
    settings: {
      blocking: {
        isEnabled: false,
        isCosmetic: false,
        whitelist: []
      }
    }
  })

  let triggered = 0
  const stop = watch(() => {
    return state.settings.blocking
  }, () => {
    triggered += 1
  })

  state.settings = {
    blocking: {
      isEnabled: true,
      isCosmetic: true,
      whitelist: []
    }
  }

  assert.is(triggered, 1)
  stop()
})

test('should not trigger when mutating parent because watching a ref that has been destroyed by the parent mutation.', (assert) => {
  let state = reactive({
    settings: {
      blocking: {
        isEnabled: false,
        isCosmetic: false,
        whitelist: []
      }
    }
  })

  let triggered = 0
  const refBlocking = ref(state.settings.blocking)
  const stop = watch(refBlocking, () => {
    triggered += 1
  })

  state.settings = {
    blocking: {
      isEnabled: true,
      isCosmetic: true,
      whitelist: []
    }
  }

  assert.is(triggered, 0)
  stop()
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions