Skip to content

Commit

Permalink
maing possible to access target in beforeEach
Browse files Browse the repository at this point in the history
  • Loading branch information
Farenheith committed Dec 14, 2019
1 parent f80fea0 commit 195a11f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build/src/strict-describe-method.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export declare class StaticMethodDescribeHelper<Target> {
export declare class MethodDescribeHelper<Target> extends StaticMethodDescribeHelper<Target> {
protected readonly bootstrap: () => Target;
constructor(bootstrap: () => Target, cls: ClassOf<Target>);
createMethodDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Target, fn: (it: MethodTestFunction<Target>) => void) => void;
createMethodDescribe(suite: (title: string, fn: () => void) => void): (method: keyof Target, fn: (it: MethodTestFunction<Target>, getTarget: () => Target) => void) => void;
createDescribe(): MethodSuite<Target>;
}
export interface BaseMethodSuite<Target> {
(methodName: keyof Target, fn: (it: MethodTestFunction<Target>) => void): any;
(methodName: keyof Target, fn: (it: MethodTestFunction<Target>, getTarget: () => Target) => void): any;
}
export interface MethodSuite<Target> extends BaseMethodSuite<Target> {
only: BaseMethodSuite<Target>;
Expand Down
2 changes: 1 addition & 1 deletion build/src/strict-describe-method.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/src/strict-describe-method.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/strict-describe-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export class MethodDescribeHelper<Target> extends StaticMethodDescribeHelper<Tar
}

createMethodDescribe(suite: (title: string, fn: () => void) => void) {
return (method: keyof Target, fn: (it: MethodTestFunction<Target>) => void) => {
return (method: keyof Target,
fn: (
it: MethodTestFunction<Target>,
getTarget: () => Target,
) => void
) => {
const wrapper = {} as TestWrapper<Target>;
const itHelper = new ItHelper(wrapper);
const it = itHelper.createIt();
Expand All @@ -66,7 +71,7 @@ export class MethodDescribeHelper<Target> extends StaticMethodDescribeHelper<Tar
);
});

fn(it);
fn(it, () => wrapper.target);

afterEach(() => {
for (const pair of backup) {
Expand All @@ -90,9 +95,8 @@ export class MethodDescribeHelper<Target> extends StaticMethodDescribeHelper<Tar
}
}


export interface BaseMethodSuite<Target> {
(methodName: keyof Target, fn: (it: MethodTestFunction<Target>) => void);
(methodName: keyof Target, fn: (it: MethodTestFunction<Target>, getTarget: () => Target) => void);
}

export interface MethodSuite<Target> extends BaseMethodSuite<Target> {
Expand Down

0 comments on commit 195a11f

Please sign in to comment.