my-own-words
Version:
A small tool that I have created to keep safe all those words/expressions that I come across when I'm learning a new language
57 lines (42 loc) • 1.49 kB
JavaScript
const os = require('os');
const rimraf = require('rimraf');
const { assert } = require('chai');
const { dirExists, listExists, getAndParseWords } = require('../src/fs-helpers');
const { newList } = require('../src/new');
const { addWord } = require('../src/add');
const home = os.homedir();
const route = `${home}\\.my-own-words`;
describe('Before #add', () => {
before(() => {
rimraf.sync(route);
});
it('should delete the directory', () => {
assert.isFalse(dirExists());
});
it('should create a clear directory with an empty list', () => {
newList('italian');
assert.isTrue(dirExists());
assert.isTrue(listExists('italian'));
});
});
describe('#add', () => {
it('should add a word into the list indicated', () => {
const listName = 'italian';
const word = 'Ciao';
addWord(listName, word, 'Hi');
assert.property(getAndParseWords(listName), word);
});
it('should add a new defintion if the word already exists into the list', () => {
const listName = 'italian';
const word = 'Ciao';
addWord(listName, word, 'Goodbye');
assert.include(getAndParseWords(listName)[word], 'Goodbye');
});
it("shouldn't add a repeated definition", () => {
const listName = 'italian';
const word = 'Ciao';
assert.lengthOf(getAndParseWords(listName)[word], 2);
assert.strictEqual(getAndParseWords(listName)[word][0], 'Goodbye');
assert.strictEqual(getAndParseWords(listName)[word][1], 'Hi');
});
});