Skip to content

Commit

Permalink
chore: fix ngCore mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Nov 9, 2021
1 parent f555718 commit 799003d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
12 changes: 8 additions & 4 deletions modules/entity/spec/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ describe('Entity utils', () => {
expect(spy).toHaveBeenCalled();
});

xit('should not warn when key does not exist in prod mode', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
it('should not warn when key does not exist in prod mode', () => {
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(false);
const spy = spyOn(console, 'warn');

const key = selectIdValue(AClockworkOrange, (book: any) => book.foo);

expect(spy).not.toHaveBeenCalled();

ngSpy.mockReset();
});

xit('should not warn when key is undefined in prod mode', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
it('should not warn when key is undefined in prod mode', () => {
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(false);
const spy = spyOn(console, 'warn');

const undefinedAClockworkOrange = { ...AClockworkOrange, id: undefined };
Expand All @@ -52,6 +54,8 @@ describe('Entity utils', () => {
);

expect(spy).not.toHaveBeenCalled();

ngSpy.mockReset();
});
});
});
14 changes: 10 additions & 4 deletions modules/store/spec/runtime_checks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('Runtime checks:', () => {
});
});

xit('should disable runtime checks in production by default', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
it('should disable runtime checks in production by default', () => {
const spy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(false);

expect(createActiveRuntimeChecks()).toEqual({
strictStateSerializability: false,
Expand All @@ -49,10 +49,13 @@ describe('Runtime checks:', () => {
strictActionWithinNgZone: false,
strictActionTypeUniqueness: false,
});

spy.mockReset();
spy.mockReturnValue(true);
});

xit('should disable runtime checks in production even if opted in to enable', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
it('should disable runtime checks in production even if opted in to enable', () => {
const spy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(false);

expect(
createActiveRuntimeChecks({
Expand All @@ -69,6 +72,9 @@ describe('Runtime checks:', () => {
strictActionWithinNgZone: false,
strictActionTypeUniqueness: false,
});

spy.mockReset();
spy.mockReturnValue(true);
});
});

Expand Down
20 changes: 14 additions & 6 deletions modules/store/spec/selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,38 +491,44 @@ describe('Selectors', () => {
});

describe('Warning', () => {
xdescribe('should not log when: ', () => {
describe('should not log when: ', () => {
it('the feature does exist', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(true);
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(true);
const selector = createFeatureSelector('featureA');

selector({ featureA: {} });

expect(warnSpy).not.toHaveBeenCalled();

ngSpy.mockReset();
});

it('the feature key exist but is falsy', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(true);
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(true);
const selector = createFeatureSelector('featureB');

selector({ featureA: {}, featureB: undefined });

expect(warnSpy).not.toHaveBeenCalled();

ngSpy.mockReset();
});

it('not in development mode', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(false);
const selector = createFeatureSelector('featureB');

selector({ featureA: {} });

expect(warnSpy).not.toHaveBeenCalled();

ngSpy.mockReset();
});
});

xdescribe('warning will ', () => {
describe('warning will ', () => {
it('be logged when not in mock environment', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(true);
const ngSpy = jest.spyOn(ngCore, 'isDevMode').mockReturnValue(true);
const selector = createFeatureSelector('featureB');

selector({ featureA: {} });
Expand All @@ -531,6 +537,8 @@ describe('Selectors', () => {
expect(warnSpy.calls.mostRecent().args[0]).toMatch(
/The feature name "featureB" does not exist/
);

ngSpy.mockReset();
});

it('not be logged when in mock environment', () => {
Expand Down

0 comments on commit 799003d

Please sign in to comment.