Skip to content

Commit

Permalink
fix(mock): fix typings error on TS 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Sep 24, 2019
1 parent fa1eff9 commit 26fc6ba
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion projects/spectator/jest/src/lib/spectator-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export function createDirectiveFactory<D, H = HostComponent>(
return baseCreateDirectiveFactory({
mockProvider,
...(isType(typeOrOptions) ? { directive: typeOrOptions } : typeOrOptions)
});
}) as SpectatorDirectiveFactory<D, H>;
}
2 changes: 1 addition & 1 deletion projects/spectator/jest/src/lib/spectator-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export function createHostFactory<C, H = HostComponent>(typeOrOptions: Type<C> |
return baseCreateHostFactory({
mockProvider,
...(isType(typeOrOptions) ? { component: typeOrOptions } : typeOrOptions)
});
}) as SpectatorHostFactory<C, H>;
}
2 changes: 1 addition & 1 deletion projects/spectator/jest/src/lib/spectator-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export function createHttpFactory<S>(typeOrOptions: SpectatorHttpOptions<S> | Ty
return baseCreateHttpFactory({
mockProvider,
...(isType(typeOrOptions) ? { dataService: typeOrOptions } : typeOrOptions)
});
}) as SpectatorHttpFactory<S>;
}
2 changes: 1 addition & 1 deletion projects/spectator/jest/src/lib/spectator-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export function createRoutingFactory<C>(typeOrOptions: SpectatorRoutingOptions<C
return baseCreateRoutingFactory({
mockProvider,
...(isType(typeOrOptions) ? { component: typeOrOptions } : typeOrOptions)
});
}) as SpectatorRoutingFactory<C>;
}
4 changes: 2 additions & 2 deletions projects/spectator/jest/src/lib/spectator-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createService<S>(typeOrOptions: SpectatorServiceOptions<S> | Typ
return baseCreateService({
mockProvider,
...(isType(typeOrOptions) ? { service: typeOrOptions } : typeOrOptions)
});
}) as SpectatorService<S>;
}

/**
Expand All @@ -40,5 +40,5 @@ export function createServiceFactory<S>(typeOrOptions: SpectatorServiceOptions<S
return baseCreateServiceFactory({
mockProvider,
...(isType(typeOrOptions) ? { service: typeOrOptions } : typeOrOptions)
});
}) as SpectatorServiceFactory<S>;
}
9 changes: 7 additions & 2 deletions projects/spectator/jest/src/lib/spectator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import {
createComponentFactory as baseCreateComponentFactory,
isType,
Spectator as BaseSpectator,
SpectatorFactory,
SpectatorOptions,
SpectatorOverrides,
Token
} from '@ngneat/spectator';

import { mockProvider, SpyObject } from './mock';

/**
* @publicApi
*/
export type SpectatorFactory<C> = (options?: SpectatorOverrides<C>) => Spectator<C>;

/**
* @deprecated Use createComponentFactory instead. To be removed in v5.
*/
Expand All @@ -21,7 +26,7 @@ export function createComponentFactory<C>(typeOrOptions: SpectatorOptions<C> | T
return baseCreateComponentFactory({
mockProvider,
...(isType(typeOrOptions) ? { component: typeOrOptions } : typeOrOptions)
});
}) as SpectatorFactory<C>;
}

export class Spectator<C> extends BaseSpectator<C> {
Expand Down
4 changes: 2 additions & 2 deletions projects/spectator/jest/test/injection-and-mocking.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createHostFactory, createService, createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { createHostFactory, createService, createComponentFactory, Spectator, SpectatorHost } from '@ngneat/spectator/jest';
import { InjectionToken } from '@angular/core';

import { ConsumerService } from '../../test/consumer.service';
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Injection tokens', () => {
]
});

let host: Spectator<ZippyComponent>;
let host: SpectatorHost<ZippyComponent>;

beforeEach(() => (host = createHost('<zippy></zippy>')));

Expand Down
23 changes: 12 additions & 11 deletions projects/spectator/src/lib/mock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/** Credit: Valentin Buryakov */
import { FactoryProvider, Type } from '@angular/core';
import { FactoryProvider } from '@angular/core';

import { InjectableType } from './token';

type Writable<T> = { -readonly [P in keyof T]: T[P] };
type Writable<T> = { -readonly [P in keyof T]: T[P] } & {
/**
* Casts to type without readonly properties
*
* @deprecated Not needed anymore as since 4.3.1 all properties of SpyObject are already writable
*/
castToWritable(): Writable<T>;
};

/**
* @publicApi
Expand All @@ -30,15 +37,9 @@ export interface CompatibleSpy extends jasmine.Spy {
/**
* @publicApi
*/
export type SpyObject<T> = Writable<T> &
{ [P in keyof Writable<T>]: T[P] extends Function ? T[P] & CompatibleSpy : T[P] } & {
/**
* Casts to type without readonly properties
*
* @deprecated Not needed anymore as since 4.3.1 all properties of SpyObject are already writable
*/
castToWritable(): Writable<T>;
};
export type SpyObject<T> = {
[P in keyof Writable<T>]: Writable<T>[P] extends Function ? Writable<T>[P] & CompatibleSpy : Writable<T>[P];
};

/**
* @internal
Expand Down

0 comments on commit 26fc6ba

Please sign in to comment.