Written tests for contains, in_array and getDomainFromUrl.

This commit is contained in:
Mario Basic
2015-06-30 17:46:37 +02:00
parent 12b153b323
commit 9598a53788
4 changed files with 32 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ function contains(line, list) {
if(cleanLine === '') continue; if(cleanLine === '') continue;
// If line contains the clean line return true // If line contains the clean line return true
if (line.indexOf(cleanLine) > - 1) { if (cleanLine.indexOf(line) > - 1) {
return true; return true;
} }
} }

View File

@@ -7,4 +7,18 @@ describe('contains', function() {
it('should be a function', function() { it('should be a function', function() {
expect(contains).to.be.a('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);
});
}); });

View File

@@ -7,4 +7,13 @@ describe('getDomainFromUrl', function() {
it('should be a function', function() { it('should be a function', function() {
expect(getDomainFromUrl).to.be.a('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');
});
}); });

View File

@@ -7,4 +7,12 @@ describe('in_array', function() {
it('should be a function', function() { it('should be a function', function() {
expect(in_array).to.be.a('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);
});
}); });