test(core): add missing tests for state services

pull/2431/head
TheDiaval 6 years ago
parent 5449e2475b
commit 2f3c43bb26

@ -3,6 +3,7 @@ import { ConfigStateService } from '../services/config-state.service';
import { ConfigState } from '../states';
import { Store } from '@ngxs/store';
import { Config } from '../models/config';
import * as ConfigActions from '../actions';
const CONFIG_STATE_DATA = {
environment: {
@ -140,4 +141,21 @@ describe('ConfigStateService', () => {
}
});
});
test('should have a dispatch method for every ConfigState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
ConfigStateService.toString()
.match(reg)
.forEach(fnName => {
expect(ConfigActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(ConfigActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new ConfigActions[fnName](...params));
});
});
});

@ -2,6 +2,8 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { ProfileStateService } from '../services/profile-state.service';
import { ProfileState } from '../states/profile.state';
import { Store } from '@ngxs/store';
import * as ProfileActions from '../actions';
describe('ProfileStateService', () => {
let service: ProfileStateService;
let spectator: SpectatorService<ProfileStateService>;
@ -35,4 +37,21 @@ describe('ProfileStateService', () => {
}
});
});
test('should have a dispatch method for every ProfileState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
ProfileStateService.toString()
.match(reg)
.forEach(fnName => {
expect(ProfileActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(ProfileActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new ProfileActions[fnName](...params));
});
});
});

@ -2,6 +2,8 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { SessionStateService } from '../services/session-state.service';
import { SessionState } from '../states/session.state';
import { Store } from '@ngxs/store';
import * as SessionActions from '../actions';
describe('SessionStateService', () => {
let service: SessionStateService;
let spectator: SpectatorService<SessionStateService>;
@ -35,4 +37,21 @@ describe('SessionStateService', () => {
}
});
});
test('should have a dispatch method for every sessionState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
SessionStateService.toString()
.match(reg)
.forEach(fnName => {
expect(SessionActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(SessionActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new SessionActions[fnName](...params));
});
});
});

Loading…
Cancel
Save