Skip to content

Commit

Permalink
work on image tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Jul 27, 2020
1 parent 3b514dc commit bd8deb7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: require.resolve('jest-environment-jsdom-sixteen'),
};
8 changes: 4 additions & 4 deletions src/__tests__/matchChart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference types="jest" />
/// <reference types="node" />

import { helpers, Chart } from '../chart';
import { Chart } from '@sgratzl/chartjs-esm-facade';
// import 'path2d-polyfill';
import { toMatchImageSnapshot } from 'jest-image-snapshot';

expect.extend({ toMatchImageSnapshot });
Expand Down Expand Up @@ -35,11 +36,10 @@ export default async function matchChart(config: any, width = 300, height = 300,
);
const ctx = canvas.getContext('2d')!;

// sync
helpers.requestAnimFrame = (c: () => void) => c();

new Chart(ctx, config);

await new Promise((resolve) => setTimeout(resolve, 100));

const image = await toBuffer(canvas);
expect(image).toMatchImageSnapshot(matchOptions);
}
27 changes: 14 additions & 13 deletions src/controllers/EulerDiagramController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { registry } from '@sgratzl/chartjs-esm-facade';
import { EulerDiagramController } from './EulerDiagramController';
import { extractSets } from '../data';
import { ArcSlice } from '../elements';
import matchChart from '../__tests__/matchChart';

describe('Euler', () => {
beforeAll(() => {
Expand All @@ -21,18 +22,18 @@ describe('Euler', () => {
}
);
expect(data.labels).toHaveLength(7);
// return matchChart(
// {
// type: EulerDiagramController.id,
// data,
// options: {
// legend: {
// display: false,
// },
// },
// },
// 1000,
// 500
// );
return matchChart(
{
type: EulerDiagramController.id,
data,
options: {
legend: {
display: false,
},
},
},
1000,
500
);
});
});
27 changes: 14 additions & 13 deletions src/controllers/VennDiagramController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { VennDiagramController } from './VennDiagramController';
import { extractSets } from '../data';
import { registry } from '@sgratzl/chartjs-esm-facade';
import { ArcSlice } from '../elements';
import matchChart from '../__tests__/matchChart';

describe('venn', () => {
beforeAll(() => {
Expand All @@ -21,18 +22,18 @@ describe('venn', () => {
}
);
expect(data.labels).toHaveLength(7);
// return matchChart(
// {
// type: VennDiagramController.id,
// data,
// options: {
// legend: {
// display: false,
// },
// },
// },
// 1000,
// 500
// );
return matchChart(
{
type: VennDiagramController.id,
data,
options: {
legend: {
display: false,
},
},
},
1000,
500
);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bd8deb7

Please sign in to comment.