UNPKG

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

82 lines (59 loc) 2.14 kB
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 { remove } = require('../src/remove'); const home = os.homedir(); const route = `${home}\\.my-own-words`; describe('Before #remove', () => { before(() => { rimraf.sync(route); }); it('should delete the directory', () => { assert.isFalse(dirExists()); }); it('should create a clear directory with an empty list', () => { const listName = 'italian'; newList(listName); assert.isTrue(dirExists()); assert.isTrue(listExists(listName)); }); it('list should have a word with two definitions', () => { const listName = 'italian'; const word = 'Ciao'; addWord(listName, word, 'Hi'); addWord(listName, word, 'Goodbye'); assert.property(getAndParseWords(listName), word); assert.include(getAndParseWords(listName)[word], 'Hi'); assert.include(getAndParseWords(listName)[word], 'Goodbye'); }); }); describe('#remove', () => { it('should return a message if the specified list does not exist', () => { const listName = 'spanish'; const word = 'Hola'; assert.strictEqual(remove(listName, word, 'Hi'), `${listName} list doesn't exists!`); }); it('should delete a list if that is the only parameter specified', () => { const listName = 'spanish'; newList(listName); assert.isTrue(listExists(listName)); remove(listName); assert.isFalse(listExists(listName)); }); it('should delete a word correctly', () => { const listName = 'italian'; const word = 'Arrivederci'; remove(listName, word); assert.notExists(getAndParseWords(listName)[word]); }); it("should delete a word's defintion correctly", () => { const listName = 'italian'; const word = 'Ciao'; remove(listName, word, 'Goodbye'); assert.include(getAndParseWords(listName)[word], 'Hi'); assert.notInclude(getAndParseWords(listName)[word], 'Goodbye'); }); });