Written tests for contains, in_array and getDomainFromUrl.
This commit is contained in:
@@ -18,7 +18,7 @@ function contains(line, list) {
|
||||
if(cleanLine === '') continue;
|
||||
|
||||
// If line contains the clean line return true
|
||||
if (line.indexOf(cleanLine) > - 1) {
|
||||
if (cleanLine.indexOf(line) > - 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,18 @@ describe('contains', function() {
|
||||
it('should be a function', function() {
|
||||
expect(contains).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should find the line and return true', function() {
|
||||
|
||||
var list = ".app\ntest.com";
|
||||
|
||||
expect(contains('.app', list)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should not find the line and it should return false', function() {
|
||||
|
||||
var list = ".app\ntest.com";
|
||||
|
||||
expect(contains('.app2', list)).to.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -7,4 +7,13 @@ describe('getDomainFromUrl', function() {
|
||||
it('should be a function', function() {
|
||||
expect(getDomainFromUrl).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return the domain', function() {
|
||||
expect(getDomainFromUrl('http://google.com/something/very/secret')).to.equal('http://google.com');
|
||||
|
||||
expect(getDomainFromUrl('http://www.google.com/something/very/secret')).to.equal('http://www.google.com');
|
||||
|
||||
// This is not how it was imaged to work, but let's leave it here as a warning.
|
||||
expect(getDomainFromUrl('google.com/something/very/secret')).to.equal('google.com//very');
|
||||
});
|
||||
});
|
||||
@@ -7,4 +7,12 @@ describe('in_array', function() {
|
||||
it('should be a function', function() {
|
||||
expect(in_array).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should find the needle and return true', function() {
|
||||
expect(in_array('4', ['4', '3', '2', '1'])).to.equal(true);
|
||||
});
|
||||
|
||||
it('should not find the needle and it should return false', function() {
|
||||
expect(in_array('5', ['4', '3', '2', '1'])).to.equal(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user