Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError on td.replace('aws-sdk') #388

Closed
4 tasks done
cwienands opened this issue Oct 20, 2018 · 2 comments
Closed
4 tasks done

TypeError on td.replace('aws-sdk') #388

cwienands opened this issue Oct 20, 2018 · 2 comments

Comments

@cwienands
Copy link

cwienands commented Oct 20, 2018

Description

I have a service that uses aws-sdk (2.278.1 right now). I would like to test-double the aws-sdk dependency in this service so that I can write true unit tests.

Issue

The td.replace('aws-sdk') call in the initialization of the test fixture throws the following exception:

 TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
  at Uint8Array.get length [as length] (<anonymous>)
  at isArrayLike (C:\Home\TestProject\node_modules\lodash\isArrayLike.js:30:42)
  at keys (C:\Home\TestProject\node_modules\lodash\keys.js:34:10)
  at baseAssign (C:\Home\TestProject\node_modules\lodash\_baseAssign.js:14:39)
  at baseClone (C:\Home\TestProject\node_modules\lodash\_baseClone.js:122:32)
  at Object.clone (C:\Home\TestProject\node_modules\lodash\clone.js:33:10)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\create-imitation.js:20:33)
  at imitate (C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:12:44)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:15:16
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:18:85
  at newValue (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:30:22)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:9:36
  at C:\Home\TestProject\node_modules\lodash\transform.js:60:12
  at C:\Home\TestProject\node_modules\lodash\_createBaseFor.js:17:11
  at baseForOwn (C:\Home\TestProject\node_modules\lodash\_baseForOwn.js:13:20)
  at Object.transform (C:\Home\TestProject\node_modules\lodash\transform.js:59:39)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:5:54)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:17:29)
  at imitate (C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:14:33)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:15:16
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:18:85
  at newValue (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:30:22)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:16:24
  at C:\Home\TestProject\node_modules\lodash\transform.js:60:12
  at C:\Home\TestProject\node_modules\lodash\_createBaseFor.js:17:11
  at baseForOwn (C:\Home\TestProject\node_modules\lodash\_baseForOwn.js:13:20)
  at Object.transform (C:\Home\TestProject\node_modules\lodash\transform.js:59:39)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:5:54)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:17:29)
  at imitate (C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:14:33)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:15:16
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:18:85
  at newValue (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:30:22)
  at C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:16:24
  at C:\Home\TestProject\node_modules\lodash\transform.js:60:12
  at C:\Home\TestProject\node_modules\lodash\_createBaseFor.js:17:11
  at baseForOwn (C:\Home\TestProject\node_modules\lodash\_baseForOwn.js:13:20)
  at Object.transform (C:\Home\TestProject\node_modules\lodash\transform.js:59:39)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\copy-props.js:5:54)
  at Object.exports.default (C:\Home\TestProject\node_modules\testdouble\lib\imitate\overwrite-children\index.js:17:29)
  at Object.imitate [as default] (C:\Home\TestProject\node_modules\testdouble\lib\imitate\index.js:14:33)
  at replaceModule (C:\Home\TestProject\node_modules\testdouble\lib\replace\module\index.js:16:38)
  at Object.default_1 [as replace] (C:\Home\TestProject\node_modules\testdouble\lib\replace\index.js:10:33)
  at Context.beforeEach (C:\Home\TestProject\test\wm\gateways\sns-gateway.spec.js:19:22)

Environment

  • node -v output: 8.11.1
  • npm -v (or yarn --version) output: 5.6.0
  • npm ls testdouble (or yarn list testdouble) version: testdouble@3.8.1
  • npm ls aws-sdk: aws-sdk@2.278.1

Failing Test

Code-fenced Examples

var td = require('testdouble');

// this call fails with the error message described above.
td.replace('aws-sdk');
@searls
Copy link
Member

searls commented Oct 20, 2018

AFAICT, this is a bug in either lodash or the custom array type used by the aws package, and outside the confines of testdouble's responsibilities. I say that because testdouble.js is not designed to fake third party libraries. Even though it often technically can replace a third-party dep, the behavior isn't supported.

For more info on why see Don't mock what you don't own. For more conversations on this, see #378, #379, #383, #316, #270

@searls searls closed this as completed Oct 20, 2018
@cwienands
Copy link
Author

Thanks for the "Don't mock..." link, and you are right about this. Coincidentally, this is exactly what I did to continue development. Wrap the aws-sdk dependency in a gateway class and mock that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants