fix testing errors

pull/10082/head
Mehmet Erim 4 years ago
parent 1edbe4b501
commit be4534b677

@ -1,10 +1,10 @@
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest';
import Chart from 'chart.js/auto';
import { ReplaySubject } from 'rxjs';
import { ChartComponent } from '../components';
import * as widgetUtils from '../utils/widget-utils';
import { chartJsLoaded$ } from '../utils/widget-utils';
// import 'chart.js';
declare const Chart;
import { ChartComponent } from './chart.component';
import * as widgetUtils from './widget-utils';
Chart
Object.defineProperty(window, 'getComputedStyle', {
value: () => ({
@ -34,19 +34,18 @@ describe('ChartComponent', () => {
},
},
});
});
test('should throw error when chart.js is not loaded', () => {
try {
spectator.component.testChartJs();
} catch (error) {
expect(error.message).toContain('Chart is not found');
}
window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}));
});
test('should have a success class by default', done => {
import('chart.js').then(() => {
chartJsLoaded$.next();
setTimeout(() => {
expect(spectator.component.chart).toBeTruthy();
done();
@ -56,7 +55,6 @@ describe('ChartComponent', () => {
describe('#reinit', () => {
it('should call the destroy method', done => {
chartJsLoaded$.next();
const spy = jest.spyOn(spectator.component.chart, 'destroy');
spectator.setHostInput({
data: {
@ -79,7 +77,6 @@ describe('ChartComponent', () => {
describe('#refresh', () => {
it('should call the update method', done => {
chartJsLoaded$.next();
const spy = jest.spyOn(spectator.component.chart, 'update');
spectator.component.refresh();
setTimeout(() => {
@ -89,38 +86,11 @@ describe('ChartComponent', () => {
});
});
describe('#generateLegend', () => {
it('should call the generateLegend method', done => {
chartJsLoaded$.next();
const spy = jest.spyOn(spectator.component.chart, 'generateLegend');
spectator.component.generateLegend();
setTimeout(() => {
expect(spy).toHaveBeenCalled();
done();
}, 0);
});
});
describe('#onCanvasClick', () => {
it('should emit the onDataSelect', done => {
spectator.component.onDataSelect.subscribe(() => {
done();
});
chartJsLoaded$.next();
jest
.spyOn(spectator.component.chart, 'getElementAtEvent')
.mockReturnValue([document.createElement('div')]);
spectator.click('canvas');
});
});
describe('#base64Image', () => {
it('should return the base64 image', done => {
chartJsLoaded$.next();
setTimeout(() => {
expect(spectator.component.base64Image).toContain('base64');
expect(spectator.component.getBase64Image()).toContain('base64');
done();
}, 0);
});

@ -1 +1,3 @@
import 'jest-canvas-mock';
import 'jest-preset-angular/setup-jest';

@ -1,9 +1,8 @@
import { DomInsertionService } from '@abp/ng.core';
import { Component } from '@angular/core';
import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { THEME_SHARED_APPEND_CONTENT } from '../tokens/append-content.token';
import { DomInsertionService } from '@abp/ng.core';
import { chartJsLoaded$ } from '../utils';
import styles from '../constants/styles';
import { THEME_SHARED_APPEND_CONTENT } from '../tokens/append-content.token';
@Component({ selector: 'abp-dummy', template: '' })
class DummyComponent {}
@ -18,13 +17,4 @@ describe('AppendContentToken', () => {
spectator.inject(THEME_SHARED_APPEND_CONTENT);
expect(spectator.inject(DomInsertionService).has(styles)).toBe(true);
});
it('should be loaded the chart.js', done => {
chartJsLoaded$.subscribe(loaded => {
expect(loaded).toBe(true);
done();
});
spectator.inject(THEME_SHARED_APPEND_CONTENT);
});
});

@ -1,2 +1,2 @@
import 'jest-canvas-mock';
import 'jest-preset-angular/setup-jest';

Loading…
Cancel
Save