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

Cannot assign to read only property 'constructor' after updating to v3.2.x #271

Closed
albertogasparin opened this issue Jun 26, 2017 · 5 comments

Comments

@albertogasparin
Copy link

I'm using td.replace to replace methods of a Koa router:

let router = new koaRouter();
td.replace(router, 'get');

The code above works fine with testdouble 3.1.x however after updating to 3.2.1 it breaks with the following error:

Cannot assign to read only property 'constructor' of object '[object Generator]'
      at exports.default (node_modules/testdouble/lib/imitate/overwrite-children/chain-prototype.js:17:27)
      at node_modules/testdouble/lib/imitate/overwrite-children/index.js:38:43
      at newValue (node_modules/testdouble/lib/imitate/overwrite-children/copy-props.js:39:20)
      at node_modules/testdouble/lib/imitate/overwrite-children/copy-props.js:18:28
      at node_modules/lodash/transform.js:60:12
      at node_modules/lodash/_createBaseFor.js:17:11
      at baseForOwn (node_modules/lodash/_baseForOwn.js:13:20)
      at Object.transform (node_modules/lodash/transform.js:59:39)
      at exports.default (node_modules/testdouble/lib/imitate/overwrite-children/copy-props.js:14:52)
      at exports.default (node_modules/testdouble/lib/imitate/overwrite-children/index.js:37:29)
      at imitate (node_modules/testdouble/lib/imitate/index.js:33:35)
      at getFake (node_modules/testdouble/lib/replace/property.js:57:34)
      at exports.default (node_modules/testdouble/lib/replace/property.js:15:37)
      at exports.default [as replace] (node_modules/testdouble/lib/replace/index.js:11:31)
      at Context.beforeEach (api/video/__tests__/unit.index.js:21:12)
      at Hook.Runnable.run (node_modules/co-mocha/lib/co-mocha.js:43:16)

Node: v6.10.3
Testdouble: v3.2.1

@searls
Copy link
Member

searls commented Jun 26, 2017

Thanks, this was a major component rewrite, so I'm not surprised to see some rough edges. I'll try to fix this ASAP. In the meantime, 3.1.x should work for you

@searls
Copy link
Member

searls commented Jun 27, 2017

Could you reproduce this on runkit or a sample app for me? I tried and failed. Here's the runkit url i used:

https://runkit.com/searls/testdouble-js---271

@albertogasparin
Copy link
Author

albertogasparin commented Jun 27, 2017

My bad, I should have written a better example. I'm using an older version of koa-router (version 7 does not use generators anymore). This is the smallest scenario I can think of:

var td = require("testdouble")

var test = {
  *method () { return 'ok' }
};

var fakeMethod = td.replace(test, 'method');

(also failing on Runkit)

@searls
Copy link
Member

searls commented Jun 27, 2017

Thanks, that'll do it! As you might surmise I didn't consider generators.

@searls
Copy link
Member

searls commented Jun 30, 2017

This was fixed in #274 & landed in 3.2.2

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