componentProxy.spec.ts 972 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { createApp, nodeOps, mockWarn } from '@vue/runtime-test'
  2. const createTestInstance = (props?: any) => {
  3. const component = {
  4. render() {}
  5. }
  6. const root = nodeOps.createElement('div')
  7. return createApp().mount(component, root, props)
  8. }
  9. describe('component proxy', () => {
  10. describe('warnings', () => {
  11. mockWarn()
  12. test('Attempting to mutate public property', () => {
  13. const app = createTestInstance()
  14. try {
  15. app.$props = { foo: 'bar' }
  16. } catch {
  17. expect(
  18. 'Attempting to mutate public property "$props". ' +
  19. 'Properties starting with $ are reserved and readonly.'
  20. ).toHaveBeenWarned()
  21. }
  22. })
  23. test('Attempting to mutate prop', () => {
  24. const app = createTestInstance({ foo: 'foo' })
  25. try {
  26. app.foo = 'bar'
  27. } catch {
  28. expect(
  29. 'Attempting to mutate prop "foo". Props are readonly.'
  30. ).toHaveBeenWarned()
  31. }
  32. })
  33. })
  34. })