这是我的效果规范文件:当我运行它时
import { TestBed } from '@angular/core/testing';
import { Actions } from '@ngrx/effects';
import { provideMockActions } from '@ngrx/effects/testing';
import { cold, hot, getTestScheduler } from 'jasmine-marbles';
import { Observable } from 'rxjs';
import * as TranslationIdAction from './../actions/translationId.action';
import { EffectsTranslationId } from './../effects/translationId.effects';
import { TranslationIdService } from './../../services/translationId-service';
import { ModelTranslationId } from './../../models/model.translationId';
describe('TranslationIdEffects', () => {
let db: any;
let effects: EffectsTranslationId;
let actions: Observable<any>;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
EffectsTranslationId,
{
provide: TranslationIdService,
useValue: { getTranslationIds: jest.fn() }
},
provideMockActions(() => actions),
]
});
db = TestBed.get(TranslationIdService);
effects = TestBed.get(EffectsTranslationId);
actions = TestBed.get(Actions);
});
describe('check the storage stupport', () => {
it('should called intial subscribe', () => {
effects.EffLoadTranslationId.subscribe();
expect(db.getTranslationIds).toHaveBeenCalled();
});
});
});
getting an error as:
jest translationId.effects.spec
console.error node_modules/jest-jasmine2/build/jasmine/Env.js:289
Unhandled error
console.error node_modules/jest-jasmine2/build/jasmine/Env.js:290
[
CallSite {}, CallSite {},
CallSite {}, CallSite {},
CallSite {}, CallSite {},
CallSite {}, CallSite {},
CallSite {}, CallSite {}
]
RUNS src/app/pf-services/state/effects/translationId.effects.spec.ts
如何解决这个问题?
我的 setup-js 文件:
// import 'jest';
import 'jest-preset-angular';
/* global mocks for jsdom */
const mock = () => {
let storage: { [key: string]: string } = {};
return {
getItem: (key: string) => (key in storage ? storage[key] : null),
setItem: (key: string, value: string) => (storage[key] = value || ''),
removeItem: (key: string) => delete storage[key],
clear: () => (storage = {})
};
};
Object.defineProperty(window, 'localStorage', { value: mock() });
Object.defineProperty(window, 'sessionStorage', { value: mock() });
Object.defineProperty(window, 'getComputedStyle', {
value: () => ['-webkit-appearance'],
});
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true,
};
},
});
/* output shorter and more meaningful Zone error stack traces */
// Error.stackTraceLimit = 2;