Created
April 18, 2015 21:07
-
-
Save ischenkodv/2869384aefb58f12efee to your computer and use it in GitHub Desktop.
Unit tests for lesson 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is module to test. | |
*/ | |
module.exports = { | |
camelCase: function(string) { | |
return string.replace(/-[a-z]/g, function(match) { | |
return match[1].toUpperCase() + match.slice(2); | |
}); | |
}, | |
dashSeparated: function(string) { | |
// Added [0-9]+ regex to add dash before numbers. | |
return string.replace(/[A-Z]|[0-9]+/g, function(match) { | |
return '-' + match.toLowerCase(); | |
}); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var strings = require('./strings'); | |
var assert = require('assert'); | |
describe('strings module', function() { | |
it('should camelCase string with onde dash correctly', function() { | |
var dashed = 'sample-string'; | |
var expected = 'sampleString'; | |
var camel = strings.camelCase(dashed); | |
assert.equal(camel, expected); | |
}); | |
it('should dash separate string with one camelCased character', function() { | |
var camel = 'sampleString'; | |
var expected = 'sample-string'; | |
var dashed = strings.dashSeparated(camel); | |
assert.equal(dashed, expected); | |
}); | |
it('should dash separate string with many camelCased character', function() { | |
var camel = 'sampleStringWithManyCamelCases'; | |
var expected = 'sample-string-with-many-camel-cases'; | |
var dashed = strings.dashSeparated(camel); | |
assert.equal(dashed, expected); | |
}); | |
it('should dash separate camel cased string with numbers', function() { | |
var camel = 'sampleStringWithNumbers1234'; | |
var expected = 'sample-string-with-numbers-1234'; | |
var dashed = strings.dashSeparated(camel); | |
assert.equal(dashed, expected); | |
}); | |
it('should dash separate camel cased string with many numbers', function() { | |
var camel = 'sampleStringWith9876ManyNumbers1234'; | |
var expected = 'sample-string-with-9876-many-numbers-1234'; | |
var dashed = strings.dashSeparated(camel); | |
assert.equal(dashed, expected); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment