describe("mailcheck", function() { var domains = ['google.com', 'gmail.com', 'emaildomain.com', 'comcast.net', 'facebook.com', 'msn.com', 'gmx.de']; var secondLevelDomains = ["yahoo", "hotmail", "mail", "live", "outlook", "gmx"]; var topLevelDomains = ['co.uk', 'com', 'org', 'info', 'fr']; describe("Mailcheck", function(){ var mailcheck; beforeEach(function(){ // We may be running in a CommonJS environment. // If so, mailcheck won't be in a global Kicksend object. mailcheck = typeof Mailcheck !== 'undefined' ? Mailcheck : require('../'); }); describe("run", function () { var suggestedSpy, emptySpy; beforeEach(function () { suggestedSpy = jasmine.createSpy(); emptySpy = jasmine.createSpy(); }); it("calls the 'suggested' callback with the element and result when there's a suggestion", function () { mailcheck.run({ email: 'test@gmail.co', suggested:suggestedSpy, empty:emptySpy }); expect(suggestedSpy).toHaveBeenCalledWith({ address:'test', domain:'gmail.com', full:'test@gmail.com' }); expect(emptySpy).not.toHaveBeenCalled(); }); it("calls the 'empty' callback with the element when there's no suggestion", function () { mailcheck.run({ email: 'contact@kicksend.com', suggested:suggestedSpy, empty:emptySpy }); expect(suggestedSpy).not.toHaveBeenCalled(); expect(emptySpy).toHaveBeenCalled(); }); it("returns the result when 'suggested' callback is not defined", function () { var result = mailcheck.run({ email: 'test@gmail.co' }); expect(result).toEqual({ address:'test', domain:'gmail.com', full:'test@gmail.com' }) }) it("takes in an array of specified domains", function () { mailcheck.run({ email: 'test@emaildomain.con', suggested:suggestedSpy, empty:emptySpy, domains:domains }); expect(suggestedSpy).toHaveBeenCalledWith({ address:'test', domain:'emaildomain.com', full:'test@emaildomain.com' }); }); }); describe("encodeEmail", function () { it("escapes the element's value", function () { var result = mailcheck.encodeEmail('@emaildomain.con'); expect(result).not.toMatch(/