Merge branch 'winh-jest-gitlab-ui' into 'master'

Make Jest work with gitlab-ui

Closes #56689

See merge request gitlab-org/gitlab-ce!25440
This commit is contained in:
Kushal Pandya 2019-02-21 11:26:05 +00:00
commit 161851de36
6 changed files with 57 additions and 33 deletions

View File

@ -1,3 +1,5 @@
/* eslint-disable import/no-commonjs, filenames/match-regex */
const BABEL_ENV = process.env.BABEL_ENV || process.env.NODE_ENV || null;
const presets = [

View File

@ -31,4 +31,5 @@ module.exports = {
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
},
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
};

View File

@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`JumpToNextDiscussionButton matches the snapshot 1`] = `
<div
class="btn-group"
role="group"
>
<button
class="btn btn-default discussion-next-btn"
data-original-title="Jump to next unresolved discussion"
title=""
>
<icon-stub
cssclasses=""
name="comment-next"
size="16"
/>
</button>
</div>
`;

View File

@ -0,0 +1,30 @@
import JumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue';
import { shallowMount } from '@vue/test-utils';
describe('JumpToNextDiscussionButton', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(JumpToNextDiscussionButton, {
sync: false,
});
});
afterEach(() => {
wrapper.destroy();
});
it('matches the snapshot', () => {
expect(wrapper.vm.$el).toMatchSnapshot();
});
it('emits onClick event on button click', () => {
const button = wrapper.find({ ref: 'button' });
button.trigger('click');
expect(wrapper.emitted()).toEqual({
onClick: [[]],
});
});
});

View File

@ -1,3 +1,5 @@
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
import axios from '~/lib/utils/axios_utils';
const testTimeoutInMs = 300;
@ -28,3 +30,5 @@ beforeEach(done => {
done();
});
Vue.use(Translate);

View File

@ -1,33 +0,0 @@
import jumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue';
import { shallowMount, createLocalVue } from '@vue/test-utils';
const localVue = createLocalVue();
describe('jumpToNextDiscussionButton', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(jumpToNextDiscussionButton, {
localVue,
sync: false,
});
});
afterEach(() => {
wrapper.destroy();
});
it('emits onClick event on button click', done => {
const button = wrapper.find({ ref: 'button' });
button.trigger('click');
localVue.nextTick(() => {
expect(wrapper.emitted()).toEqual({
onClick: [[]],
});
done();
});
});
});