@vue/test-utils#shallowMount JavaScript Examples

The following examples show how to use @vue/test-utils#shallowMount. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwoColumnMultiSelect.test.js    From pollen with MIT License 6 votes vote down vote up
describe('TwoColumnMultiSelect', () => {
  test('renders correctly', () => {
    const wrapper = shallowMount(TwoColumnMultiSelect, {
      propsData: {
        options,
        name: 'test',
      },
    });
    expect(wrapper.element).toMatchSnapshot();
  });

  test('emits event when user clicks an item ', () => {
    const wrapper = mount(TwoColumnMultiSelect, {
      propsData: {
        options,
        name: 'test',
      },
    });
    const option = wrapper.find('[data-qa="test-input"]');
    option.trigger('click');
    expect(wrapper.emitted().input).toBeTruthy();
  });
});
Example #2
Source File: color-mode.spec.js    From kanban-app with MIT License 6 votes vote down vote up
describe('ColorMode', () => {
  test('is a Vue instance', () => {
    const wrapper = shallowMount(ColorMode, {
      mocks: {
        $colorMode: colorMode,
      },
    })

    expect(wrapper.vm).toBeTruthy()
  })
})
Example #3
Source File: Hamburger.spec.js    From SystemManagement with MIT License 6 votes vote down vote up
describe('Hamburger.vue', () => {
  it('toggle click', () => {
    const wrapper = shallowMount(Hamburger)
    const mockFn = jest.fn()
    wrapper.vm.$on('toggleClick', mockFn)
    wrapper.find('.hamburger').trigger('click')
    expect(mockFn).toBeCalled()
  })
  it('prop isActive', () => {
    const wrapper = shallowMount(Hamburger)
    wrapper.setProps({ isActive: true })
    expect(wrapper.contains('.is-active')).toBe(true)
    wrapper.setProps({ isActive: false })
    expect(wrapper.contains('.is-active')).toBe(false)
  })
})
Example #4
Source File: SkillsLevel.test.js    From skills-client with Apache License 2.0 6 votes vote down vote up
describe('SkillsLevel', () => {
  describe('rendering', () => {
    it('only renders once skillsLevel is initialized', async () => {
      SkillsConfiguration.afterConfigure.mockImplementation(() => new Promise(() => { }))
      const wrapper = shallowMount(SkillsLevel);
      const selector = '.skills-level-text-display';

      expect(wrapper.find(selector).isVisible()).toBe(false);

      await wrapper.setData({ skillLevel: 1 });

      expect(wrapper.find(selector).isVisible()).toBe(true);
    });
  });
});
Example #5
Source File: auditlog.spec.js    From SSO_Project with GNU General Public License v3.0 6 votes vote down vote up
wrapper = shallowMount(AuditLog, {
	mocks: {
		$t: key => key,
		$i18n: {
			locale: "en",
		},
	},
	parentComponent: {
		data() {
			return {
				user: {
					session: "session",
				},
			};
		},
		methods: {
			apiPost,
			apiGet,
		},
	},
	stubs: [
		"country-flag",
	],
})
Example #6
Source File: Exercise1-01.spec.js    From Front-End-Development-Projects-with-Vue.js with MIT License 6 votes vote down vote up
describe('Exercise1-01.vue', () => {
  it('renders props.title when passed', () => {
    const title = 'My first component!'
    const wrapper = shallowMount(Exercise, {
      propsData: { title },
    })
    expect(wrapper.text()).toMatch(title)
  })
})
Example #7
Source File: InfiniteButton.spec.js    From infinite-ui with MIT License 6 votes vote down vote up
describe('InfiniteButton.vue', () => {
  const props = getTestData()
  const wrapper = shallowMount(InfiniteButton, {
    propsData: {
      type: props.type,
      plain: props.plain,
      round: props.round,
      size: props.size
    },
    slots: {
      default: '测试按钮'
    },
    stubs: {
      ElButton
    }
  })

  it('event cancel clicked focus', async () => {
    const spanEl = wrapper.find('span')
    await spanEl.trigger('click')
    expect(wrapper.vm.handleClick).toBeTruthy()
  })
})
Example #8
Source File: App.spec.js    From common-forms-toolkit with Apache License 2.0 6 votes vote down vote up
describe('Secure.vue', () => {
  let vuetify;

  beforeEach(() => {
    vuetify = new Vuetify();
  });

  it('renders', () => {
    const wrapper = shallowMount(Secure, {
      vuetify,
      stubs: ['BaseSecure', 'BCGovFooter', 'BCGovHeader', 'router-view']
    });

    expect(wrapper.html()).toMatch('v-main');
  });
});
Example #9
Source File: App.spec.js    From common-hosted-form-service with Apache License 2.0 6 votes vote down vote up
describe('App.vue', () => {
  let vuetify;

  beforeEach(() => {
    vuetify = new Vuetify();
  });

  it('renders', () => {
    const wrapper = shallowMount(App, {
      vuetify,
      stubs: ['BaseNotificationContainer', 'BaseSecure', 'BCGovFooter', 'BCGovHeader', 'BCGovNavBar', 'router-view']
    });

    expect(wrapper.text()).toMatch('');
  });
});
Example #10
Source File: App.spec.js    From silviculture-ipc with Apache License 2.0 6 votes vote down vote up
describe('App.vue', () => {
  it('renders', () => {
    const wrapper = shallowMount(App, {
      localVue,
      stubs: [
        'BCGovHeader',
        'BCGovNavBar',
        'BCGovFooter'
      ]
    });

    expect(wrapper.text()).toMatch('');
    expect(wrapper.html()).toMatch('v-app');
    expect(wrapper.html()).toMatch('router-view');
  });
});
Example #11
Source File: App.spec.js    From vue-scaffold with Apache License 2.0 6 votes vote down vote up
describe('Secure.vue', () => {
  let vuetify;

  beforeEach(() => {
    vuetify = new Vuetify();
  });

  it('renders', () => {
    const wrapper = shallowMount(Secure, {
      vuetify,
      stubs: ['BaseSecure', 'BCGovFooter', 'BCGovHeader', 'BCGovNavBar', 'router-view']
    });

    expect(wrapper.text()).toMatch('');
  });
});