diff --git a/package.json b/package.json index f2f44f2..082bb68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-autobind", - "version": "0.1.0", + "version": "0.2.0", "description": "it binds methods to its class prototype + Compatible with stub/spy used on unit-test frameworks (Sinon.Js, enzyme,...so on) + Can be integrated with 3rd party decorators (like @autobind decorator)", "main": "index.js", "scripts": { @@ -30,7 +30,8 @@ "addon", "unit-test", "expect", - "autobind-decorator" + "autobind-decorator", + "enzyme" ], "author": "Abdennour TOUMI ", "license": "MIT", diff --git a/src/index.js b/src/index.js index 103fc6c..f304d4c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -export function Autobind(Mocked) { +export function Autobind(Mocked, sameName) { const methods = Object.getOwnPropertyNames(Mocked.prototype); const methodsExcluded = ['constructor', 'render']; const ruleIncluder = (methodName => @@ -14,5 +14,16 @@ export function Autobind(Mocked) { }); } } + if(sameName) { + const rename = (() => { + Object.defineProperty(Mocker, 'name', { + writable: true + }); + Mocker.name = (Mocked.name && Mocked.name.length) ? Mocked.name : 'Component'; + Object.defineProperty(Mocker, 'name', { + writable: false + }); + })(); + } return Mocker; }; diff --git a/test/Spec.js b/test/Spec.js index acd1902..e56ee49 100644 --- a/test/Spec.js +++ b/test/Spec.js @@ -66,4 +66,12 @@ describe(`babel-autobind`, () => { wrapper.instance().handleClick({}); }).toNotThrow(); }); + + it(`rename the bound class to be the same as the name of the original class`, () => { + let Target = Autobind(ComponentWithoutBinding); + expect(Target.name).toNotEqual('ComponentWithoutBinding'); + Target = Autobind(ComponentWithoutBinding, true); + expect(Target.name).toEqual('ComponentWithoutBinding'); + }); + }); diff --git a/test/examples.js b/test/examples.js deleted file mode 100644 index 93dd092..0000000 --- a/test/examples.js +++ /dev/null @@ -1,7 +0,0 @@ -import {autobind} from '../src'; -import React from 'react'; - - - - -//--------------