@ -39,7 +39,7 @@ const globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
|
||||
const testBed = getTestBed();
|
||||
|
||||
export type TestFn = ((done: DoneFn) => any) | (() => any);
|
||||
export type TestFn = ((done: DoneFn) => any)|(() => any);
|
||||
|
||||
/**
|
||||
* Mechanism to run `beforeEach()` functions of Angular tests.
|
||||
@ -51,20 +51,26 @@ class BeforeEachRunner {
|
||||
|
||||
constructor(private _parent: BeforeEachRunner) {}
|
||||
|
||||
beforeEach(fn: Function): void { this._fns.push(fn); }
|
||||
beforeEach(fn: Function): void {
|
||||
this._fns.push(fn);
|
||||
}
|
||||
|
||||
run(): void {
|
||||
if (this._parent) this._parent.run();
|
||||
this._fns.forEach((fn) => { fn(); });
|
||||
this._fns.forEach((fn) => {
|
||||
fn();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the test providers before each test
|
||||
jsmBeforeEach(() => { testBed.resetTestingModule(); });
|
||||
jsmBeforeEach(() => {
|
||||
testBed.resetTestingModule();
|
||||
});
|
||||
|
||||
function _describe(jsmFn: Function, ...args: any[]) {
|
||||
const parentRunner = runnerStack.length === 0 ? null : runnerStack[runnerStack.length - 1];
|
||||
const runner = new BeforeEachRunner(parentRunner !);
|
||||
const runner = new BeforeEachRunner(parentRunner!);
|
||||
runnerStack.push(runner);
|
||||
const suite = jsmFn(...args);
|
||||
runnerStack.pop();
|
||||
@ -138,7 +144,7 @@ function _it(jsmFn: Function, testName: string, testFn: TestFn, testTimeout = 0)
|
||||
if (testFn.length === 0) {
|
||||
// TypeScript doesn't infer the TestFn type without parameters here, so we
|
||||
// need to manually cast it.
|
||||
const retVal = (testFn as() => any)();
|
||||
const retVal = (testFn as () => any)();
|
||||
if (isPromise(retVal)) {
|
||||
// Asynchronous test function that returns a Promise - wait for completion.
|
||||
retVal.then(done, done.fail);
|
||||
@ -192,7 +198,9 @@ export class SpyObject {
|
||||
return (this as any)[name];
|
||||
}
|
||||
|
||||
prop(name: string, value: any) { (this as any)[name] = value; }
|
||||
prop(name: string, value: any) {
|
||||
(this as any)[name] = value;
|
||||
}
|
||||
|
||||
static stub(object: any = null, config: any = null, overrides: any = null) {
|
||||
if (!(object instanceof SpyObject)) {
|
||||
@ -202,7 +210,9 @@ export class SpyObject {
|
||||
}
|
||||
|
||||
const m = {...config, ...overrides};
|
||||
Object.keys(m).forEach(key => { object.spy(key).and.returnValue(m[key]); });
|
||||
Object.keys(m).forEach(key => {
|
||||
object.spy(key).and.returnValue(m[key]);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user