diff --git a/package.json b/package.json index 713d6cb..34b5fe5 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "eslint-plugin-react": "~4.2.3", "expect.js": "~0.3.1", "mocha": "~2.4.5", + "proxyquire": "~1.7.4", "sinon": "~1.17.3" }, "dependencies": { diff --git a/src/index.js b/src/index.js index d1a3b7e..94ab2ae 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import { omit } from 'lodash'; export default class Elastique extends events.EventEmitter { constructor(options = {}) { if (!options.index) throw new Error('Must specify an index to write to'); + super(); this.ready = true; diff --git a/test/helpers/create_client.js b/test/helpers/create_client.js new file mode 100644 index 0000000..11a94e0 --- /dev/null +++ b/test/helpers/create_client.js @@ -0,0 +1,28 @@ +import expect from 'expect.js'; +import proxyquire from 'proxyquire'; + +const elasticsearchMock = { + Client: function Client() {} +}; + +const createClient = proxyquire.noPreserveCache()('../../lib/helpers/create_client', { + elasticsearch: elasticsearchMock +}); + +describe('Create client helper', function () { + it('should have a client', function () { + const options = { + host: 'http://localhost:9200' + }; + const client = createClient(options); + + expect(client).to.be.a(elasticsearchMock.Client); + }); + + it('should use passed in instance', function () { + const clientInstance = new elasticsearchMock.Client(); + const client = createClient(clientInstance); + + expect(client).to.equal(clientInstance); + }); +});