{"action":"closed","issue":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/46","labels_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/46/comments","events_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/46/events","html_url":"https://github.com/vitaly-t/pg-promise/issues/46","id":109071376,"number":46,"title":"The new locks feature introduces in 1.10.3 made unit test mocking/stubbing impossible","user":{"login":"jniemin","id":2638877,"avatar_url":"https://avatars.githubusercontent.com/u/2638877?v=3","gravatar_id":"","url":"https://api.github.com/users/jniemin","html_url":"https://github.com/jniemin","followers_url":"https://api.github.com/users/jniemin/followers","following_url":"https://api.github.com/users/jniemin/following{/other_user}","gists_url":"https://api.github.com/users/jniemin/gists{/gist_id}","starred_url":"https://api.github.com/users/jniemin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jniemin/subscriptions","organizations_url":"https://api.github.com/users/jniemin/orgs","repos_url":"https://api.github.com/users/jniemin/repos","events_url":"https://api.github.com/users/jniemin/events{/privacy}","received_events_url":"https://api.github.com/users/jniemin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/requires%20feedback","name":"requires feedback","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-30T11:51:16Z","updated_at":"2015-10-01T07:57:37Z","closed_at":"2015-10-01T07:57:37Z","body":"When the locks was introduced it also added side effect that mocking libraries like Sinon.js cannot create mocks from db object. Now mocking library throws error \"TypeError: Cannot redefine property:\" as locking also sets configurable property to false for functions. Here is the test case that worked with at least version 1.4.4 but now with latest 1.10.7 is broken with TypeError error\r\n\r\n```javascript\r\nvar chai = require(\"chai\");\r\nvar assert = chai.assert;\r\nvar sinon = require(\"sinon\");\r\nvar pgpLib = require('pg-promise');\r\n\r\ndescribe(\"Database query\", function(){\r\n\r\n  it(\"health check executed correct\", function(){\r\n    var pgp = pgpLib();\r\n    var cn = {\r\n      host: 'localhost', // server name or IP address;\r\n      port: 5432,\r\n      database: 'my_db_name',\r\n      user: 'user_name',\r\n      password: 'user_password'\r\n    };\r\n    var db = pgp(cn);\r\n    var stub = sinon.stub(db, \"one\");\r\n    var sqlString = \"SELECT $1::int AS number\";\r\n    var params = [\"1\"];\r\n    db.one(\"SELECT $1::int AS number\", [\"1\"]);\r\n    assert.isTrue(stub.calledWith(sqlString, params), \"one should have been called\");\r\n    stub.restore();\r\n  });\r\n});\r\n``` "}}