From e92cbae330f310b6af88a42d4ef2b93112f605a3 Mon Sep 17 00:00:00 2001 From: Harm van der Werf Date: Mon, 11 Jun 2018 10:06:14 +0200 Subject: [PATCH 1/2] Made "on" function compatible with current plugin version --- types/chai-spies/chai-spies-tests.ts | 7 ++++++- types/chai-spies/index.d.ts | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/types/chai-spies/chai-spies-tests.ts b/types/chai-spies/chai-spies-tests.ts index 1d99f0add2..dcff5a9cdd 100644 --- a/types/chai-spies/chai-spies-tests.ts +++ b/types/chai-spies/chai-spies-tests.ts @@ -24,7 +24,12 @@ let array = [ 1, 2, 3 ]; chai.spy.on(array, 'push'); // or you can track multiple object's methods -chai.spy.on(array, 'push', 'pop'); +chai.spy.on(array, ['push', 'pop']); + +// or you can track multiple object's methods +chai.spy.on(array, 'push', function(item) { + array.push(item); +}); array.push(5); diff --git a/types/chai-spies/index.d.ts b/types/chai-spies/index.d.ts index ffed6e594b..1ad4a5c76a 100644 --- a/types/chai-spies/index.d.ts +++ b/types/chai-spies/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for chai-spies // Project: https://github.com/chaijs/chai-spies // Definitions by: Ilya Kuznetsov +// Harm van der Werf // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -81,10 +82,11 @@ declare namespace ChaiSpies { * var spy = chai.spy.on(Array, 'isArray'); * ``` * @param {Object} object - * @param {String} method name to spy on + * @param {String} methodNames name to spy on + * @param {function} fn replacement function * @returns function to actually call - */ - on(object: Object, ...methodNames: string[]): any; + */ + on(object: Object, methodNames: string | string[], fn?: (parameters: any) => any): any; /** * #### chai.spy.object (function) @@ -97,10 +99,10 @@ declare namespace ChaiSpies { * @param {String[]|Object} method names or method definitions * @returns object with spied methods */ - object(name: string, methods: string[]): any; - object(methods: string[]): any; - object(name: string, methods: T): T; - object(methods: T): T; + object(name: string, methods: string[]): any; + object(methods: string[]): any; + object(name: string, methods: T): T; + object(methods: T): T; /** * #### chai.spy.returns (function) From e58013cfe54bc6b55ceb57171d50345987c40a6e Mon Sep 17 00:00:00 2001 From: Harm van der Werf Date: Mon, 11 Jun 2018 10:42:59 +0200 Subject: [PATCH 2/2] Fixed an error --- types/chai-spies/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chai-spies/index.d.ts b/types/chai-spies/index.d.ts index 1ad4a5c76a..ba7798b714 100644 --- a/types/chai-spies/index.d.ts +++ b/types/chai-spies/index.d.ts @@ -86,7 +86,7 @@ declare namespace ChaiSpies { * @param {function} fn replacement function * @returns function to actually call */ - on(object: Object, methodNames: string | string[], fn?: (parameters: any) => any): any; + on(object: Object, methodNames: string | string[], fn?: (parameters: any[]) => any): any; /** * #### chai.spy.object (function)