Skip to content

Commit

Permalink
Fix DoubleObjectWithKey type; add respective test; Rename generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ojeda committed May 11, 2017
1 parent 3e895af commit e86769c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// types and interfaces
// ----------------------------------------------------------------------------

export type DoubledObject<Subject> = Subject;
export type DoubledObject<T> = T;

export type DoubledObjectWithKey<Key extends string> = {};
export type DoubledObjectWithKey<T extends string> = { [K in T] };

export type TestDouble<Function> = Function;
export type TestDouble<T> = T;

export type TestDoubleConstructor<T> = Constructor<T>;

Expand Down Expand Up @@ -156,7 +156,7 @@ export function object<T>(constructor: Constructor<T> ): DoubledObject<T>;
* @param {Key[]} props Array of properties.
* @returns {DoubledObjectWithKey<Key>}
*/
export function object<Key extends string>(props: Key[]): DoubledObjectWithKey<Key>;
export function object<T extends string>(props: T[]): DoubledObjectWithKey<T>;

/**
* Create a fake empty object that is cast as the generic using a Proxy object.
Expand Down
4 changes: 4 additions & 0 deletions test/src/typescript/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ td.when(dog.bark()).thenReturn("bark!");

// td.object()

const cat = td.object(["scratch","meow"]);
td.when(cat.scratch()).thenReturn("scratch!");
td.when(cat.meow()).thenReturn("meow!");

const bird = td.object({ fly: function(){} });
td.when(bird.fly()).thenReturn("fly!");

Expand Down

0 comments on commit e86769c

Please sign in to comment.