var $ = require('cheerio');
var chai = require('chai');
var expect = chai.expect;
var fs = require('fs');

var getUniqueSelector = require('../src/get-unique-selector.js').init();

function compareElementsForSelector($html, classSelector) {
  var findUsingUniqueSelector = $html.find($.getUniqueSelector($html.find(classSelector)));
  var findUsingClass          = $html.find(classSelector);
  var isSameElement           = findUsingClass.is(findUsingUniqueSelector);
  expect(isSameElement).to.be.true;
  expect(findUsingUniqueSelector).to.have.lengthOf(1); // Only one selected element
}

describe('Get Unique Selector', () => {
  var htmlString = fs.readFileSync('./test/fixtures/example.html', 'utf8');
  var $html = $(htmlString);

  it('should get the unique selector for normal LI', () => {

    compareElementsForSelector($html, '.test1');
  });

  it('should get the unique selector for element with ID', () => {
    compareElementsForSelector($html, '.test2');
  });

  it('should get the unique selector for element with ID ANCESTOR', () => {
    compareElementsForSelector($html, '.test3');
  });

  it('should get the unique selector for BODY', () => {
    compareElementsForSelector($html, '.test4');
  });

  it('should get the unique selector for span with id under other id', () => {
    compareElementsForSelector($html, '.test5');
  });

  it('should get the unique selector for span under multiple anchestors with an id', () => {
    compareElementsForSelector($html, '.test6');
  });

  it('should get the unique selector for the first span', () => {
    compareElementsForSelector($html, '.test7');
  });

  it('should get the unique selector using the :last-child selector', () => {
    compareElementsForSelector($html, '.test8');
  });
});

@@ -1,13 +1,19 @@
 var 
-$
+cheerio
  = requi
@@ -110,17 +110,17 @@
 );%0A%0Avar 
-g
+G
 etUnique
@@ -174,16 +174,8 @@
 js')
-.init();
 %0A%0Afu
@@ -209,20 +209,16 @@
 lector($
-html
 , classS
@@ -247,66 +247,26 @@
 sing
-UniqueSelector = $html.find($.getUniqueSelector($html.find
+Class          = $
 (cla
@@ -276,18 +276,16 @@
 elector)
-))
 ;%0A  var 
@@ -297,49 +297,59 @@
 sing
-Class          = $html.find(class
+UniqueSelector = $(findUsingClass.getUnique
 Selector
 );%0A 
@@ -336,32 +336,34 @@
 etUniqueSelector
+()
 );%0A  var isSameE
@@ -675,16 +675,23 @@
 ar $
-html = $
+ = cheerio.load
 (htm
@@ -787,36 +787,32 @@
 ntsForSelector($
-html
 , '.test1');%0A  %7D
@@ -906,36 +906,32 @@
 ntsForSelector($
-html
 , '.test2');%0A  %7D
@@ -1034,36 +1034,32 @@
 ntsForSelector($
-html
 , '.test3');%0A  %7D
@@ -1142,36 +1142,32 @@
 ntsForSelector($
-html
 , '.test4');%0A  %7D
@@ -1273,36 +1273,32 @@
 ntsForSelector($
-html
 , '.test5');%0A  %7D
@@ -1418,36 +1418,32 @@
 ntsForSelector($
-html
 , '.test6');%0A  %7D
@@ -1536,36 +1536,32 @@
 ntsForSelector($
-html
 , '.test7');%0A  %7D
@@ -1674,20 +1674,16 @@
 lector($
-html
 , '.test

Update index.js