Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
2
test/words/words.js
Normal file
2
test/words/words.js
Normal file
@ -0,0 +1,2 @@
|
||||
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
||||
module.exports = words;
|
||||
21
test/words/words.test.js
Normal file
21
test/words/words.test.js
Normal file
@ -0,0 +1,21 @@
|
||||
const expect = require('expect');
|
||||
const words = require('./words.js');
|
||||
|
||||
|
||||
test('words is a Function', () => {
|
||||
expect(words).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(words('I love javaScript!!'), ["I", "love", "javaScript"], "words('I love javaScript!!') returns [I, love, javaScript]");
|
||||
t.deepEqual(words('python, javaScript & coffee'), ["python", "javaScript", "coffee"], "words('python, javaScript & coffee') returns [python, javaScript, coffee]");
|
||||
test('words(I love javaScript!!) returns an array', () => {
|
||||
expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy();
|
||||
});
|
||||
t.throws(() => words(), 'words() throws a error');
|
||||
t.throws(() => words(null), 'words(null) throws a error');
|
||||
t.throws(() => words(undefined), 'words(undefined) throws a error');
|
||||
t.throws(() => words({}), 'words({}) throws a error');
|
||||
t.throws(() => words([]), 'words([]) throws a error');
|
||||
t.throws(() => words(1234), 'words(1234) throws a error');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user