summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Arias <farias@gitlab.com>2019-04-03 14:53:08 -0500
committerFernando Arias <farias@gitlab.com>2019-04-03 14:53:08 -0500
commitbe821f1f3b7143c2d506c2b53f42efb878fa141d (patch)
tree15b40b4f4a8f56b0919776dc2524e3a7063ed64a
parent6747799af3cae69a99029db6e530e498f5957383 (diff)
downloadgitlab-ce-resize-vuln-graph.tar.gz
Make code review changesresize-vuln-graph
* Make mocked function parmeter more generic * Don't use random numbers in unit tests * Add comment about JSDOM workaround
-rw-r--r--spec/frontend/vue_shared/components/resizable_chart_container_spec.js26
1 files changed, 12 insertions, 14 deletions
diff --git a/spec/frontend/vue_shared/components/resizable_chart_container_spec.js b/spec/frontend/vue_shared/components/resizable_chart_container_spec.js
index dd18ce9dcb7..8f533e8ab24 100644
--- a/spec/frontend/vue_shared/components/resizable_chart_container_spec.js
+++ b/spec/frontend/vue_shared/components/resizable_chart_container_spec.js
@@ -4,8 +4,8 @@ import ResizableChartContainer from '~/vue_shared/components/resizable_chart/res
import $ from 'jquery';
jest.mock('~/lib/utils/common_utils', () => ({
- debounceByAnimationFrame(onResize) {
- return jest.spyOn({ onResize }, 'onResize');
+ debounceByAnimationFrame(callback) {
+ return jest.spyOn({ callback }, 'callback');
},
}));
@@ -34,24 +34,22 @@ describe('Resizable Chart Container', () => {
expect(wrapper.element).toMatchSnapshot();
});
- it('updates the slot width and height props', done => {
- const width = Math.floor(Math.random() * 1000);
- const height = Math.floor(Math.random() * 1000);
+ it('updates the slot width and height props', () => {
+ const width = 1920;
+ const height = 1080;
+ // JSDOM mocks and sets clientWidth/clientHeight to 0 so we set manually
wrapper.vm.$refs.chartWrapper = { clientWidth: width, clientHeight: height };
$(document).trigger('content.resize');
- Vue.nextTick()
- .then(() => {
- const widthNode = wrapper.find('.slot > .width');
- const heightNode = wrapper.find('.slot > .height');
+ return Vue.nextTick().then(() => {
+ const widthNode = wrapper.find('.slot > .width');
+ const heightNode = wrapper.find('.slot > .height');
- expect(parseInt(widthNode.text(), 10)).toEqual(width);
- expect(parseInt(heightNode.text(), 10)).toEqual(height);
- done();
- })
- .catch(done.fail);
+ expect(parseInt(widthNode.text(), 10)).toEqual(width);
+ expect(parseInt(heightNode.text(), 10)).toEqual(height);
+ });
});
it('calls onResize on manual resize', () => {