mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Rewrite unit test waitForResize helper (#4566)
The original implementation tries to intercept events from the chart internal iframe, which ones failing on Chrome 60. Checking internals doesn't seem the best approach, instead we could consider that a chart has been resized after the resize method has been called and processed. So let's hook `Chart.resize` and callback once it's done.
This commit is contained in:
parent
3aa7a20923
commit
c6bda02468
@ -22,13 +22,8 @@ sudo: required
|
|||||||
dist: trusty
|
dist: trusty
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
|
chrome: stable
|
||||||
firefox: latest
|
firefox: latest
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- google-chrome
|
|
||||||
packages:
|
|
||||||
- google-chrome-stable
|
|
||||||
|
|
||||||
|
|
||||||
# IMPORTANT: scripts require GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
|
# IMPORTANT: scripts require GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
|
||||||
# IMPORTANT: scripts has to be set executables in the Git repository (error 127)
|
# IMPORTANT: scripts has to be set executables in the Git repository (error 127)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ globals:
|
|||||||
acquireChart: true
|
acquireChart: true
|
||||||
Chart: true
|
Chart: true
|
||||||
moment: true
|
moment: true
|
||||||
|
waitForResize: true
|
||||||
|
|
||||||
# http://eslint.org/docs/rules/
|
# http://eslint.org/docs/rules/
|
||||||
rules:
|
rules:
|
||||||
|
|||||||
@ -24,6 +24,7 @@ var utils = require('./jasmine.utils');
|
|||||||
|
|
||||||
window.acquireChart = acquireChart;
|
window.acquireChart = acquireChart;
|
||||||
window.releaseChart = releaseChart;
|
window.releaseChart = releaseChart;
|
||||||
|
window.waitForResize = utils.waitForResize;
|
||||||
window.createMockContext = createMockContext;
|
window.createMockContext = createMockContext;
|
||||||
|
|
||||||
// some style initialization to limit differences between browsers across different plateforms.
|
// some style initialization to limit differences between browsers across different plateforms.
|
||||||
|
|||||||
@ -149,10 +149,20 @@ function specsFromFixtures(path) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitForResize(chart, callback) {
|
||||||
|
var override = chart.resize;
|
||||||
|
chart.resize = function() {
|
||||||
|
chart.resize = override;
|
||||||
|
override.apply(this, arguments);
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
injectCSS: injectCSS,
|
injectCSS: injectCSS,
|
||||||
createCanvas: createCanvas,
|
createCanvas: createCanvas,
|
||||||
acquireChart: acquireChart,
|
acquireChart: acquireChart,
|
||||||
releaseChart: releaseChart,
|
releaseChart: releaseChart,
|
||||||
specsFromFixtures: specsFromFixtures
|
specsFromFixtures: specsFromFixtures,
|
||||||
|
waitForResize: waitForResize
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,18 +1,5 @@
|
|||||||
describe('Chart', function() {
|
describe('Chart', function() {
|
||||||
|
|
||||||
function waitForResize(chart, callback) {
|
|
||||||
var resizer = chart.canvas.parentNode._chartjs.resizer;
|
|
||||||
var content = resizer.contentWindow || resizer;
|
|
||||||
var state = content.document.readyState || 'complete';
|
|
||||||
var handler = function() {
|
|
||||||
Chart.helpers.removeEvent(content, 'load', handler);
|
|
||||||
Chart.helpers.removeEvent(content, 'resize', handler);
|
|
||||||
setTimeout(callback, 50);
|
|
||||||
};
|
|
||||||
|
|
||||||
Chart.helpers.addEvent(content, state !== 'complete' ? 'load' : 'resize', handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/chartjs/Chart.js/issues/2481
|
// https://github.com/chartjs/Chart.js/issues/2481
|
||||||
// See global.deprecations.tests.js for backward compatibility
|
// See global.deprecations.tests.js for backward compatibility
|
||||||
it('should be defined and prototype of chart instances', function() {
|
it('should be defined and prototype of chart instances', function() {
|
||||||
|
|||||||
@ -1,18 +1,5 @@
|
|||||||
describe('Platform.dom', function() {
|
describe('Platform.dom', function() {
|
||||||
|
|
||||||
function waitForResize(chart, callback) {
|
|
||||||
var resizer = chart.canvas.parentNode._chartjs.resizer;
|
|
||||||
var content = resizer.contentWindow || resizer;
|
|
||||||
var state = content.document.readyState || 'complete';
|
|
||||||
var handler = function() {
|
|
||||||
Chart.helpers.removeEvent(content, 'load', handler);
|
|
||||||
Chart.helpers.removeEvent(content, 'resize', handler);
|
|
||||||
setTimeout(callback, 50);
|
|
||||||
};
|
|
||||||
|
|
||||||
Chart.helpers.addEvent(content, state !== 'complete' ? 'load' : 'resize', handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('context acquisition', function() {
|
describe('context acquisition', function() {
|
||||||
var canvasId = 'chartjs-canvas';
|
var canvasId = 'chartjs-canvas';
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user