From cdad91ffe1768f5791279fd382424314a0ff8153 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 19 Dec 2016 23:09:09 +0000 Subject: [PATCH] Replace should.js assertions with Chai Chai is more popular and so has more examples for getting in-browser tests run from the command line (I haven't found any for should.js) using third-party modules, which will be more helpful than sticking with should.js. The only downside is that chai doesn't have neat Promise assertions, and the chai-as-promised plugin that adds them doesn't support browsers without something like Browserify involved. --- package.json | 4 +- src/tests/gui/html/js/test.html | 7 +- src/tests/gui/html/js/test_filters.js | 87 +++++++------- src/tests/gui/html/js/test_game.js | 54 ++++----- src/tests/gui/html/js/test_plugin.js | 122 +++++++++---------- src/tests/gui/html/js/test_query.js | 29 +++-- src/tests/gui/html/js/test_state.js | 130 ++++++++++----------- src/tests/gui/html/js/test_translator.js | 4 +- src/tests/gui/html/js/test_updateExists.js | 72 +++++++----- 9 files changed, 270 insertions(+), 239 deletions(-) diff --git a/package.json b/package.json index f90edcec..504db28c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "devDependencies": { "bower": "^1.7.1", + "chai": "^3.5.0", "eslint": "^3.5.0", "eslint-config-airbnb-base": "^7.1.0", "eslint-plugin-import": "^1.15.0", @@ -32,8 +33,7 @@ "grunt-contrib-watch": "^1.0.0", "grunt-saucelabs": "^9.0.0", "mkdirp": "^0.5.1", - "mocha": "^3.0.1", - "should": "^11.1.0" + "mocha": "^3.0.1" }, "scripts": { "test": "grunt test" diff --git a/src/tests/gui/html/js/test.html b/src/tests/gui/html/js/test.html index 9f7a3115..392b8722 100644 --- a/src/tests/gui/html/js/test.html +++ b/src/tests/gui/html/js/test.html @@ -4,14 +4,17 @@
- + - + diff --git a/src/tests/gui/html/js/test_filters.js b/src/tests/gui/html/js/test_filters.js index 8d81f164..12640fae 100644 --- a/src/tests/gui/html/js/test_filters.js +++ b/src/tests/gui/html/js/test_filters.js @@ -30,17 +30,17 @@ describe('Filters', () => { it('should initialise filters as not enabled', () => { const filters = new loot.Filters(l10n); - filters.hideMessagelessPlugins.should.be.false(); - filters.hideInactivePlugins.should.be.false(); - filters.conflictingPluginNames.should.deepEqual([]); + filters.hideMessagelessPlugins.should.be.false; + filters.hideInactivePlugins.should.be.false; + filters.conflictingPluginNames.should.deep.equal([]); filters.contentSearchString.should.equal(''); - filters.hideVersionNumbers.should.be.false(); - filters.hideCRCs.should.be.false(); - filters.hideBashTags.should.be.false(); - filters.hideAllPluginMessages.should.be.false(); - filters.hideNotes.should.be.false(); - filters.hideDoNotCleanMessages.should.be.false(); + filters.hideVersionNumbers.should.be.false; + filters.hideCRCs.should.be.false; + filters.hideBashTags.should.be.false; + filters.hideAllPluginMessages.should.be.false; + filters.hideNotes.should.be.false; + filters.hideDoNotCleanMessages.should.be.false; }); it('should initialise "do not clean" search string', () => { @@ -92,41 +92,41 @@ describe('Filters', () => { }); it('should return true if no filters are enabled', () => { - filters.pluginFilter(plugin).should.be.true(); + filters.pluginFilter(plugin).should.be.true; }); it('should return false if inactive plugins filter is enabled', () => { filters.hideInactivePlugins = true; - filters.pluginFilter(plugin).should.be.false(); + filters.pluginFilter(plugin).should.be.false; }); it('should return true if inactive plugins filter is enabled and plugin is active', () => { filters.hideInactivePlugins = true; plugin.isActive = true; - filters.pluginFilter(plugin).should.be.true(); + filters.pluginFilter(plugin).should.be.true; }); it('should return false if messageless plugins filter is enabled', () => { filters.hideMessagelessPlugins = true; - filters.pluginFilter(plugin).should.be.false(); + filters.pluginFilter(plugin).should.be.false; }); it('should return true if messageless plugins filter is enabled and plugin has a non-zero message array', () => { filters.hideMessagelessPlugins = true; plugin.messages = [0]; - filters.pluginFilter(plugin).should.be.true(); + filters.pluginFilter(plugin).should.be.true; }); it('should return false if all plugin messages and messageless plugin filters are enabled and plugin has a non-zero message array', () => { filters.hideAllPluginMessages = true; filters.hideMessagelessPlugins = true; plugin.messages = [0]; - filters.pluginFilter(plugin).should.be.false(); + filters.pluginFilter(plugin).should.be.false; }); it('should return false if conflicting plugins filter is enabled', () => { filters.conflictingPluginNames = ['conflicting plugin']; - filters.pluginFilter(plugin).should.be.false(); + filters.pluginFilter(plugin).should.be.false; }); it('should return true if conflicting plugins filter is enabled and plugin name is in the conflicting plugins array', () => { @@ -134,17 +134,17 @@ describe('Filters', () => { 'conflicting plugin', plugin.name, ]; - filters.pluginFilter(plugin).should.be.true(); + filters.pluginFilter(plugin).should.be.true; }); it('should return false if plugin content filter is enabled', () => { filters.contentSearchString = 'unfound text'; - filters.pluginFilter(plugin).should.be.false(); + filters.pluginFilter(plugin).should.be.false; }); it('should return true if plugin content filter is enabled and plugin contains the filter text', () => { filters.contentSearchString = 'found text'; - filters.pluginFilter(plugin).should.be.true(); + filters.pluginFilter(plugin).should.be.true; }); }); @@ -166,41 +166,41 @@ describe('Filters', () => { }); it('should return true for a note message when no filters are enabled', () => { - filters.messageFilter(note).should.be.true(); + filters.messageFilter(note).should.be.true; }); it('should return true for a warning "do not clean" message when no filters are enabled', () => { - filters.messageFilter(doNotCleanMessage).should.be.true(); + filters.messageFilter(doNotCleanMessage).should.be.true; }); it('should return false for a note message when the notes filter is enabled', () => { filters.hideNotes = true; - filters.messageFilter(note).should.be.false(); + filters.messageFilter(note).should.be.false; }); it('should return true for a warning message when the notes filter is enabled', () => { filters.hideNotes = true; - filters.messageFilter(doNotCleanMessage).should.be.true(); + filters.messageFilter(doNotCleanMessage).should.be.true; }); it('should return false for a "do not clean" message when the "do not clean" messages filter is enabled', () => { filters.hideDoNotCleanMessages = true; - filters.messageFilter(doNotCleanMessage).should.be.false(); + filters.messageFilter(doNotCleanMessage).should.be.false; }); it('should return true for a message not containing "do not clean" when the "do not clean" messages filter is enabled', () => { filters.hideDoNotCleanMessages = true; - filters.messageFilter(note).should.be.true(); + filters.messageFilter(note).should.be.true; }); it('should return false for a note message when the all messages filter is enabled', () => { filters.hideAllPluginMessages = true; - filters.messageFilter(note).should.be.false(); + filters.messageFilter(note).should.be.false; }); it('should return false for a "do not clean" message when the all messages filter is enabled', () => { filters.hideAllPluginMessages = true; - filters.messageFilter(doNotCleanMessage).should.be.false(); + filters.messageFilter(doNotCleanMessage).should.be.false; }); }); @@ -217,19 +217,19 @@ describe('Filters', () => { }); it('should return false if the conflicts filter was not active', () => { - filters.deactivateConflictsFilter().should.be.false(); + filters.deactivateConflictsFilter().should.be.false; }); it('should return true if the conflicts filter was active', () => { filters.conflictingPluginNames = ['Skyrim.esm']; - filters.deactivateConflictsFilter().should.be.true(); + filters.deactivateConflictsFilter().should.be.true; }); it('should empty the conflicting plugin names array', () => { filters.conflictingPluginNames = ['Skyrim.esm']; - filters.deactivateConflictsFilter().should.be.true(); + filters.deactivateConflictsFilter().should.be.true; filters.conflictingPluginNames.should.have.length(0); }); @@ -252,7 +252,10 @@ describe('Filters', () => { }); it('should return a promise that resolves to an empty array if the argument is falsy', () => { - filters.activateConflictsFilter().should.finally.deepEqual([]); + filters.activateConflictsFilter().then((result) => { + result.should.be.an('array'); + return result.should.be.empty; + }); }); }); @@ -264,67 +267,67 @@ describe('Filters', () => { }); it('should return false if all the boolean filters are false, and the content and conflict filter lengths are zero', () => { - filters.areAnyFiltersActive().should.be.false(); + filters.areAnyFiltersActive().should.be.false; }); it('should return true if hideMessagelessPlugins is true', () => { filters.hideMessagelessPlugins = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideInactivePlugins is true', () => { filters.hideInactivePlugins = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideVersionNumbers is true', () => { filters.hideVersionNumbers = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideCRCs is true', () => { filters.hideCRCs = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideBashTags is true', () => { filters.hideBashTags = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideAllPluginMessages is true', () => { filters.hideAllPluginMessages = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideNotes is true', () => { filters.hideNotes = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if hideDoNotCleanMessages is true', () => { filters.hideDoNotCleanMessages = true; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if conflictingPluginNames is a non-empty array', () => { filters.conflictingPluginNames = ['foo']; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); it('should return true if contentSearchString is a non-empty string', () => { filters.contentSearchString = 'foo'; - filters.areAnyFiltersActive().should.be.true(); + filters.areAnyFiltersActive().should.be.true; }); }); }); diff --git a/src/tests/gui/html/js/test_game.js b/src/tests/gui/html/js/test_game.js index 7a254f63..af7caa6e 100644 --- a/src/tests/gui/html/js/test_game.js +++ b/src/tests/gui/html/js/test_game.js @@ -38,52 +38,52 @@ describe('Game', () => { it('should set globalMessages to an empty array by default', () => { const game = new loot.Game({}, l10n); - game.globalMessages.should.deepEqual([]); + game.globalMessages.should.deep.equal([]); }); it('should set globalMessages to the object\'s value if defined', () => { const game = new loot.Game({ globalMessages: ['test'] }, l10n); - game.globalMessages.should.deepEqual(['test']); + game.globalMessages.should.deep.equal(['test']); }); it('should set masterlist to an empty object by default', () => { const game = new loot.Game({}, l10n); - game.masterlist.should.deepEqual({}); + game.masterlist.should.deep.equal({}); }); it('should set masterlist to the object\'s value if defined', () => { const game = new loot.Game({ masterlist: { revision: 0 } }, l10n); - game.masterlist.should.deepEqual({ revision: 0 }); + game.masterlist.should.deep.equal({ revision: 0 }); }); it('should set plugins to an empty array by default', () => { const game = new loot.Game({}, l10n); - game.plugins.should.deepEqual([]); + game.plugins.should.deep.equal([]); }); it('should set plugins to the object\'s value if defined', () => { const game = new loot.Game({ plugins: ['test'] }, l10n); - game.plugins.should.deepEqual(['test']); + game.plugins.should.deep.equal(['test']); }); it('should set loadOrder to undefined by default', () => { const game = new loot.Game({}, l10n); - should(game.loadOrder).be.undefined(); + should.equal(undefined, game.loadOrder); }); it('should set loadOrder to undefined even if the object\'s value if defined', () => { const game = new loot.Game({ loadOrder: ['test'] }, l10n); - should(game.loadOrder).be.undefined(); + should.equal(undefined, game.loadOrder); }); it('should set oldLoadOrder to undefined by default', () => { const game = new loot.Game({}, l10n); - should(game.oldLoadOrder).be.undefined(); + should.equal(undefined, game.oldLoadOrder); }); it('should set oldLoadOrder to undefined even if the object\'s value if defined', () => { const game = new loot.Game({ oldLoadOrder: ['test'] }, l10n); - should(game.oldLoadOrder).be.undefined(); + should.equal(undefined, game.oldLoadOrder); }); it('should initialise _notApplicableString', () => { @@ -153,7 +153,7 @@ describe('Game', () => { { type: 'error' }, ]; handleEvent = (evt) => { - evt.detail.messages.should.deepEqual(newMessages); + evt.detail.messages.should.deep.equal(newMessages); evt.detail.totalDiff.should.equal(2); evt.detail.errorDiff.should.equal(1); evt.detail.warningDiff.should.equal(1); @@ -193,7 +193,7 @@ describe('Game', () => { date: 'bar', }; handleEvent = (evt) => { - evt.detail.should.deepEqual(newMasterlist); + evt.detail.should.deep.equal(newMasterlist); done(); }; document.addEventListener('loot-game-masterlist-change', handleEvent); @@ -246,7 +246,7 @@ describe('Game', () => { }, ]; handleEvent = (evt) => { - evt.detail.valuesAreTotals.should.be.true(); + evt.detail.valuesAreTotals.should.be.true; evt.detail.totalMessageNo.should.equal(4); evt.detail.warnMessageNo.should.equal(2); evt.detail.errorMessageNo.should.equal(1); @@ -286,12 +286,12 @@ describe('Game', () => { }; game.appendPlugin(newPlugin); - game.plugins[0].should.deepEqual(newPlugin); + game.plugins[0].should.deep.equal(newPlugin); }); it('should dispatch an event with the correct counter differences', (done) => { handleEvent = (evt) => { - evt.detail.valuesAreTotals.should.be.false(); + evt.detail.valuesAreTotals.should.be.false; evt.detail.totalMessageNo.should.equal(1); evt.detail.warnMessageNo.should.equal(1); evt.detail.errorMessageNo.should.equal(0); @@ -338,7 +338,7 @@ describe('Game', () => { it('should dispatch an event with the correct counter differences', (done) => { handleEvent = (evt) => { - evt.detail.valuesAreTotals.should.be.false(); + evt.detail.valuesAreTotals.should.be.false; evt.detail.totalMessageNo.should.equal(-1); evt.detail.warnMessageNo.should.equal(-1); evt.detail.errorMessageNo.should.equal(0); @@ -367,7 +367,7 @@ describe('Game', () => { }); it('should return an object of two empty arrays if there is no game data', () => { - game.getContent().should.deepEqual({ + game.getContent().should.deep.equal({ messages: [], plugins: [], }); @@ -407,7 +407,7 @@ describe('Game', () => { _isSearchResult: true, }]; - game.getContent().should.deepEqual({ + game.getContent().should.deep.equal({ messages: game._globalMessages, plugins: [{ name: game._plugins[0].name, @@ -435,7 +435,7 @@ describe('Game', () => { }); it('should return an empty array if there are no plugins', () => { - game.getPluginNames().should.be.empty(); + game.getPluginNames().should.be.empty; }); it('should return an array of plugin filenames if there are plugins', () => { @@ -445,7 +445,7 @@ describe('Game', () => { messages: [{ type: 'warn' }], }]; - game.getPluginNames().should.deepEqual(['foo']); + game.getPluginNames().should.deep.equal(['foo']); }); }); @@ -482,7 +482,7 @@ describe('Game', () => { }]); game.plugins[0].crc.should.equal(0xDEADBEEF); - game.plugins[0].isActive.should.be.true(); + game.plugins[0].isActive.should.be.true; }); it('should reorder plugins to given order', () => { @@ -543,7 +543,7 @@ describe('Game', () => { game.applySort(); - should(game.oldLoadOrder).be.undefined(); + should.equal(undefined, game.oldLoadOrder); }); }); @@ -573,7 +573,7 @@ describe('Game', () => { game.cancelSort([]); - game.plugins.should.deepEqual(oldLoadOrder); + game.plugins.should.deep.equal(oldLoadOrder); }); it('should delete the stored old load order', () => { @@ -585,7 +585,7 @@ describe('Game', () => { game.cancelSort([]); - should(game.oldLoadOrder).be.undefined(); + should.equal(undefined, game.oldLoadOrder); }); it('should set plugin load order indices using the array passed as the first parameter', () => { @@ -616,7 +616,7 @@ describe('Game', () => { game.cancelSort([], ['foo']); - game.globalMessages.should.deepEqual(['foo']); + game.globalMessages.should.deep.equal(['foo']); }); }); @@ -637,7 +637,7 @@ describe('Game', () => { name: 'foo', }]); - should(game.plugins[0].userlist).be.undefined(); + should.equal(undefined, game.plugins[0].userlist); }); it('should update existing plugin data', () => { @@ -652,7 +652,7 @@ describe('Game', () => { }]); game.plugins[0].crc.should.equal(0xDEADBEEF); - game.plugins[0].isActive.should.be.true(); + game.plugins[0].isActive.should.be.true; }); }); }); diff --git a/src/tests/gui/html/js/test_plugin.js b/src/tests/gui/html/js/test_plugin.js index 3cdfae8c..3c97d23f 100644 --- a/src/tests/gui/html/js/test_plugin.js +++ b/src/tests/gui/html/js/test_plugin.js @@ -81,7 +81,7 @@ describe('Plugin', () => { it('should set isActive value to false if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isActive.should.be.false(); + plugin.isActive.should.be.false; }); it('should set isActive to passed key\'s value', () => { @@ -90,13 +90,13 @@ describe('Plugin', () => { isActive: true, }); - plugin.isActive.should.be.true(); + plugin.isActive.should.be.true; }); it('should set isEmpty value to false if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isEmpty.should.be.false(); + plugin.isEmpty.should.be.false; }); it('should set isEmpty to passed key\'s value', () => { @@ -105,13 +105,13 @@ describe('Plugin', () => { isEmpty: true, }); - plugin.isEmpty.should.be.true(); + plugin.isEmpty.should.be.true; }); it('should set isMaster value to false if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isMaster.should.be.false(); + plugin.isMaster.should.be.false; }); it('should set isMaster to passed key\'s value', () => { @@ -120,13 +120,13 @@ describe('Plugin', () => { isMaster: true, }); - plugin.isMaster.should.be.true(); + plugin.isMaster.should.be.true; }); it('should set loadsArchive value to false if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.loadsArchive.should.be.false(); + plugin.loadsArchive.should.be.false; }); it('should set loadsArchive to passed key\'s value', () => { @@ -135,13 +135,13 @@ describe('Plugin', () => { loadsArchive: true, }); - plugin.loadsArchive.should.be.true(); + plugin.loadsArchive.should.be.true; }); it('should set masterlist value to undefined if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - should(plugin.masterlist).be.undefined(); + should.equal(undefined, plugin.masterlist); }); it('should set masterlist to passed key\'s value', () => { @@ -150,13 +150,13 @@ describe('Plugin', () => { masterlist: {}, }); - plugin.masterlist.should.be.deepEqual({}); + plugin.masterlist.should.be.deep.equal({}); }); it('should set userlist value to undefined if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - should(plugin.userlist).be.undefined(); + should.equal(undefined, plugin.userlist); }); it('should set userlist to passed key\'s value', () => { @@ -165,7 +165,7 @@ describe('Plugin', () => { userlist: {}, }); - plugin.userlist.should.be.deepEqual({}); + plugin.userlist.should.be.deep.equal({}); }); it('should set priority to 0 if no key was passed', () => { @@ -214,7 +214,7 @@ describe('Plugin', () => { messages, }); - plugin.messages.should.deepEqual(messages); + plugin.messages.should.deep.equal(messages); }); it('should set tags value to an empty array if no key was passed', () => { @@ -232,13 +232,13 @@ describe('Plugin', () => { tags, }); - plugin.tags.should.deepEqual(tags); + plugin.tags.should.deep.equal(tags); }); it('should set isDirty value to false if no key was passed', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isDirty.should.be.false(); + plugin.isDirty.should.be.false; }); it('should set isDirty to passed key\'s value', () => { @@ -247,7 +247,7 @@ describe('Plugin', () => { isDirty: true, }); - plugin.isDirty.should.be.true(); + plugin.isDirty.should.be.true; }); it('should set cleanedWith value to an empty string if no key was passed', () => { @@ -274,13 +274,13 @@ describe('Plugin', () => { it('should set isEditorOpen to false', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isEditorOpen.should.be.false(); + plugin.isEditorOpen.should.be.false; }); it('should set isSearchResult to false', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isSearchResult.should.be.false(); + plugin.isSearchResult.should.be.false; }); }); @@ -299,15 +299,15 @@ describe('Plugin', () => { it('should do nothing if its argument is undefined', () => { plugin.update(); - plugin.should.deepEqual(new loot.Plugin({ name: 'test' })); + plugin.should.deep.equal(new loot.Plugin({ name: 'test' })); }); it('should throw if the argument has no name property', () => { - should(() => { plugin.update({}); }).throw(Error); + (() => { plugin.update({}); }).should.throw(Error); }); it('should throw if the argument\'s name property doesn\'t match the plugin\'s name', () => { - should(() => { plugin.update({ name: 'other test' }); }).throw(Error); + (() => { plugin.update({ name: 'other test' }); }).should.throw(Error); }); it('should set property values for all the given argument\'s properties', () => { @@ -324,7 +324,7 @@ describe('Plugin', () => { plugin.foo.should.equal(updatedPlugin.foo); plugin.crc.should.equal(updatedPlugin.crc); - plugin.isActive.should.be.true(); + plugin.isActive.should.be.true; }); it('should set explicitly undefined values', () => { @@ -335,7 +335,7 @@ describe('Plugin', () => { isActive: undefined, }); - should(plugin.isActive).be.undefined(); + should.equal(undefined, plugin.isActive); }); }); @@ -347,7 +347,7 @@ describe('Plugin', () => { }; const testInputJson = JSON.stringify(testInputObj); - JSON.parse(testInputJson, loot.Plugin.fromJson).should.deepEqual(testInputObj); + JSON.parse(testInputJson, loot.Plugin.fromJson).should.deep.equal(testInputObj); }); it('should return a Plugin object if the JSON is of the Plugin type', () => { @@ -376,7 +376,7 @@ describe('Plugin', () => { condition: 'foo', type: 'remove', name: 'bar', - }).should.deepEqual({ + }).should.deep.equal({ condition: 'foo', name: '-bar', }); @@ -387,7 +387,7 @@ describe('Plugin', () => { condition: 'foo', type: 'add', name: 'bar', - }).should.deepEqual({ + }).should.deep.equal({ condition: 'foo', name: 'bar', }); @@ -407,7 +407,7 @@ describe('Plugin', () => { loot.Plugin.tagToRowData({ condition: 'foo', name: '-bar', - }).should.deepEqual({ + }).should.deep.equal({ condition: 'foo', type: 'remove', name: 'bar', @@ -418,7 +418,7 @@ describe('Plugin', () => { loot.Plugin.tagToRowData({ condition: 'foo', name: 'bar', - }).should.deepEqual({ + }).should.deep.equal({ condition: 'foo', type: 'add', name: 'bar', @@ -445,8 +445,8 @@ describe('Plugin', () => { messages: [], }); - plugin.messages.should.be.Array(); - plugin.messages.should.be.empty(); + plugin.messages.should.be.an('array'); + plugin.messages.should.be.empty; }); it('getting messages should return any that are set', () => { @@ -459,7 +459,7 @@ describe('Plugin', () => { messages, }); - plugin.messages.should.be.deepEqual(messages); + plugin.messages.should.be.deep.equal(messages); }); it('setting messages should store any set', () => { @@ -474,7 +474,7 @@ describe('Plugin', () => { plugin.messages = messages; - plugin.messages.should.be.deepEqual(messages); + plugin.messages.should.be.deep.equal(messages); }); it('setting messages should not fire an event if no messages were changed', (done) => { @@ -531,7 +531,7 @@ describe('Plugin', () => { it('getting value should return false if isDirty has not been set in the constructor', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isDirty.should.be.false(); + plugin.isDirty.should.be.false; }); it('getting value should return true if isDirty is set to true in the constructor', () => { @@ -540,7 +540,7 @@ describe('Plugin', () => { isDirty: true, }); - plugin.isDirty.should.be.true(); + plugin.isDirty.should.be.true; }); it('setting value should store set value', () => { @@ -548,7 +548,7 @@ describe('Plugin', () => { plugin.isDirty = true; - plugin.isDirty.should.be.true(); + plugin.isDirty.should.be.true; }); it('setting value to the current value should not fire an event', (done) => { @@ -569,7 +569,7 @@ describe('Plugin', () => { const plugin = new loot.Plugin({ name: 'test' }); handleEvent = (evt) => { - evt.detail.isDirty.should.be.true(); + evt.detail.isDirty.should.be.true; done(); }; @@ -717,7 +717,7 @@ describe('Plugin', () => { tags, }); - plugin.tags.should.deepEqual(tags); + plugin.tags.should.deep.equal(tags); }); it('setting value should store set value', () => { @@ -728,7 +728,7 @@ describe('Plugin', () => { plugin.tags = tags; - plugin.tags.should.deepEqual(tags); + plugin.tags.should.deep.equal(tags); }); it('setting value to the current value should not fire an event', (done) => { @@ -772,7 +772,7 @@ describe('Plugin', () => { it('getting value should return undefined if it has not been set in the constructor', () => { const plugin = new loot.Plugin({ name: 'test' }); - should(plugin.userlist).be.undefined(); + should.equal(undefined, plugin.userlist); }); it('getting value should return the value that was set', () => { @@ -781,7 +781,7 @@ describe('Plugin', () => { userlist: {}, }); - plugin.userlist.should.deepEqual({}); + plugin.userlist.should.deep.equal({}); }); it('setting value should store set value', () => { @@ -789,7 +789,7 @@ describe('Plugin', () => { plugin.userlist = {}; - plugin.userlist.should.deepEqual({}); + plugin.userlist.should.deep.equal({}); }); it('setting value to the current value should not fire an event', (done) => { @@ -958,7 +958,7 @@ describe('Plugin', () => { it('getting value should return false if it has not been set in the constructor', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isEditorOpen.should.be.false(); + plugin.isEditorOpen.should.be.false; }); it('setting value should store set value', () => { @@ -966,7 +966,7 @@ describe('Plugin', () => { plugin.isEditorOpen = true; - plugin.isEditorOpen.should.be.true(); + plugin.isEditorOpen.should.be.true; }); it('setting value to the current value should not fire an event', (done) => { @@ -1011,7 +1011,7 @@ describe('Plugin', () => { it('getting value should return false if it has not been set in the constructor', () => { const plugin = new loot.Plugin({ name: 'test' }); - plugin.isSearchResult.should.be.false(); + plugin.isSearchResult.should.be.false; }); it('setting value should store set value', () => { @@ -1019,7 +1019,7 @@ describe('Plugin', () => { plugin.isSearchResult = true; - plugin.isSearchResult.should.be.true(); + plugin.isSearchResult.should.be.true; }); it('setting value to the current value should not fire an event', (done) => { @@ -1167,7 +1167,7 @@ describe('PluginCardContent', () => { describe('#tags', () => { it('should return an object containing empty strings if no tags are set', () => { - plugin.getCardContent(filters).tags.should.deepEqual({ + plugin.getCardContent(filters).tags.should.deep.equal({ added: '', removed: '', }); @@ -1182,7 +1182,7 @@ describe('PluginCardContent', () => { { name: '-Actor.ABCS' }, ]; - plugin.getCardContent(filters).tags.should.deepEqual({ + plugin.getCardContent(filters).tags.should.deep.equal({ added: 'Relev, Delev, Names', removed: 'C.Climate, Actor.ABCS', }); @@ -1198,7 +1198,7 @@ describe('PluginCardContent', () => { ]; filters.hideBashTags = true; - plugin.getCardContent(filters).tags.should.deepEqual({ + plugin.getCardContent(filters).tags.should.deep.equal({ added: '', removed: '', }); @@ -1210,7 +1210,7 @@ describe('PluginCardContent', () => { { name: '-Relev' }, ]; - plugin.getCardContent(filters).tags.should.deepEqual({ + plugin.getCardContent(filters).tags.should.deep.equal({ added: '', removed: 'Relev', }); @@ -1263,26 +1263,26 @@ describe('PluginCardContent', () => { describe('#messages', () => { it('should return message objects mapped from the plugin\'s message objects', () => { - plugin.getCardContent(filters).messages.should.deepEqual(plugin.messages); + plugin.getCardContent(filters).messages.should.deep.equal(plugin.messages); }); it('should return an array missing the note message when the notes filter is enabled', () => { filters.hideNotes = true; - plugin.getCardContent(filters).messages.should.deepEqual([ + plugin.getCardContent(filters).messages.should.deep.equal([ plugin.messages[1], ]); }); it('should return an array missing the "do not clean" message when the "do not clean" messages filter is enabled', () => { filters.hideDoNotCleanMessages = true; - plugin.getCardContent(filters).messages.should.deepEqual([ + plugin.getCardContent(filters).messages.should.deep.equal([ plugin.messages[0], ]); }); it('should return an empty array when the all messages filter is enabled', () => { filters.hideAllPluginMessages = true; - plugin.getCardContent(filters).messages.should.deepEqual([]); + plugin.getCardContent(filters).messages.should.deep.equal([]); }); it('setting value should throw', () => { @@ -1292,20 +1292,20 @@ describe('PluginCardContent', () => { describe('#containsText()', () => { it('should return true if argument is undefined', () => { - plugin.getCardContent(filters).containsText().should.be.true(); + plugin.getCardContent(filters).containsText().should.be.true; }); it('should return true if argument is an empty string', () => { - plugin.getCardContent(filters).containsText('').should.be.true(); + plugin.getCardContent(filters).containsText('').should.be.true; }); it('should search name case-insensitively', () => { - plugin.getCardContent(filters).containsText('Tes').should.be.true(); + plugin.getCardContent(filters).containsText('Tes').should.be.true; }); it('should search CRC case-insensitively', () => { plugin.crc = 0xDEADBEEF; - plugin.getCardContent(filters).containsText('dead').should.be.true(); + plugin.getCardContent(filters).containsText('dead').should.be.true; }); it('should search added tags case-insensitively', () => { @@ -1316,7 +1316,7 @@ describe('PluginCardContent', () => { { name: '-C.Climate' }, { name: '-Actor.ABCS' }, ]; - plugin.getCardContent(filters).containsText('climate').should.be.true(); + plugin.getCardContent(filters).containsText('climate').should.be.true; }); it('should search removed tags case-insensitively', () => { @@ -1327,15 +1327,15 @@ describe('PluginCardContent', () => { { name: '-C.Climate' }, { name: '-Actor.ABCS' }, ]; - plugin.getCardContent(filters).containsText('.abc').should.be.true(); + plugin.getCardContent(filters).containsText('.abc').should.be.true; }); it('should search message content case-insensitively', () => { - plugin.getCardContent(filters).containsText('Clean').should.be.true(); + plugin.getCardContent(filters).containsText('Clean').should.be.true; }); it('should not find text that is not present', () => { - plugin.getCardContent(filters).containsText('say').should.be.false(); + plugin.getCardContent(filters).containsText('say').should.be.false; }); }); }); diff --git a/src/tests/gui/html/js/test_query.js b/src/tests/gui/html/js/test_query.js index 6c0ba222..0a06cfb0 100644 --- a/src/tests/gui/html/js/test_query.js +++ b/src/tests/gui/html/js/test_query.js @@ -15,25 +15,32 @@ describe('query()', () => { }); it('should return a promise', () => { - loot.query('test').should.be.a.Promise(); // eslint-disable-line new-cap + loot.query('test').should.be.a('promise'); // eslint-disable-line new-cap }); it('should succeed if a request name is passed', () => - loot.query('test').should.be.fulfilledWith('{"name":"test","args":[]}') + loot.query('test').then((result) => + result.should.equal('{"name":"test","args":[]}') + ) ); it('should succeed if a request name and arguments are passed', () => - loot.query('test', 1, false, ['a']).should.be.fulfilledWith(JSON.stringify({ - name: 'test', - args: [ - 1, - false, - ['a'], - ], - })) + loot.query('test', 1, false, ['a']).then((result) => + result.should.equal(JSON.stringify({ + name: 'test', + args: [ + 1, + false, + ['a'], + ], + })) + ) ); it('should fail with an Error object when an error occurs', () => - loot.query('fail').should.be.rejectedWith(Error, { message: '{"name":"fail","args":[]}' }) + loot.query('fail').catch((error) => { + error.should.be.an('error'); + return error.message.should.equal('{"name":"fail","args":[]}'); + }) ); }); diff --git a/src/tests/gui/html/js/test_state.js b/src/tests/gui/html/js/test_state.js index 3efd3170..1ca9e883 100644 --- a/src/tests/gui/html/js/test_state.js +++ b/src/tests/gui/html/js/test_state.js @@ -45,21 +45,21 @@ describe('State', () => { it('should return true if the default state is the current state', () => { const state = new loot.State(); - state.isInDefaultState().should.be.true(); + state.isInDefaultState().should.be.true; }); it('should return false if the editing state is the current state', () => { const state = new loot.State(); state.enterEditingState(); - state.isInDefaultState().should.be.false(); + state.isInDefaultState().should.be.false; }); it('should return false if the sorting state is the current state', () => { const state = new loot.State(); state.enterSortingState(); - state.isInDefaultState().should.be.false(); + state.isInDefaultState().should.be.false; }); }); @@ -68,20 +68,20 @@ describe('State', () => { const state = new loot.State(); state.enterEditingState(); - state.isInEditingState().should.be.true(); + state.isInEditingState().should.be.true; }); it('should return false if the default state is the current state', () => { const state = new loot.State(); - state.isInEditingState().should.be.false(); + state.isInEditingState().should.be.false; }); it('should return false if the sorting state is the current state', () => { const state = new loot.State(); state.enterSortingState(); - state.isInEditingState().should.be.false(); + state.isInEditingState().should.be.false; }); }); @@ -90,20 +90,20 @@ describe('State', () => { const state = new loot.State(); state.enterSortingState(); - state.isInSortingState().should.be.true(); + state.isInSortingState().should.be.true; }); it('should return false if the editing state is the current state', () => { const state = new loot.State(); state.enterEditingState(); - state.isInSortingState().should.be.false(); + state.isInSortingState().should.be.false; }); it('should return false if the default state is the current state', () => { const state = new loot.State(); - state.isInSortingState().should.be.false(); + state.isInSortingState().should.be.false; }); }); @@ -114,12 +114,12 @@ describe('State', () => { state.currentState.should.equal(loot.State.SORTING_STATE); - getShown('updateMasterlistButton').should.be.false(); - getShown('sortButton').should.be.false(); - getShown('applySortButton').should.be.true(); - getShown('cancelSortButton').should.be.true(); - getEnabled('gameMenu').should.be.false(); - getEnabled('refreshContentButton').should.be.false(); + getShown('updateMasterlistButton').should.be.false; + getShown('sortButton').should.be.false; + getShown('applySortButton').should.be.true; + getShown('cancelSortButton').should.be.true; + getEnabled('gameMenu').should.be.false; + getEnabled('refreshContentButton').should.be.false; getDomState().should.equal('sorting'); }); @@ -128,7 +128,7 @@ describe('State', () => { const state = new loot.State(); state.enterEditingState(); - should.throws(() => { state.enterSortingState(); }, Error); + should.throw(() => { state.enterSortingState(); }, Error); }); it('should have no effect if already in the sorting state', () => { @@ -138,12 +138,12 @@ describe('State', () => { state.currentState.should.equal(loot.State.SORTING_STATE); - getShown('updateMasterlistButton').should.be.false(); - getShown('sortButton').should.be.false(); - getShown('applySortButton').should.be.true(); - getShown('cancelSortButton').should.be.true(); - getEnabled('gameMenu').should.be.false(); - getEnabled('refreshContentButton').should.be.false(); + getShown('updateMasterlistButton').should.be.false; + getShown('sortButton').should.be.false; + getShown('applySortButton').should.be.true; + getShown('cancelSortButton').should.be.true; + getEnabled('gameMenu').should.be.false; + getEnabled('refreshContentButton').should.be.false; }); }); @@ -155,12 +155,12 @@ describe('State', () => { state.currentState.should.equal(loot.State.DEFAULT_STATE); - getShown('updateMasterlistButton').should.be.true(); - getShown('sortButton').should.be.true(); - getShown('applySortButton').should.be.false(); - getShown('cancelSortButton').should.be.false(); - getEnabled('gameMenu').should.be.true(); - getEnabled('refreshContentButton').should.be.true(); + getShown('updateMasterlistButton').should.be.true; + getShown('sortButton').should.be.true; + getShown('applySortButton').should.be.false; + getShown('cancelSortButton').should.be.false; + getEnabled('gameMenu').should.be.true; + getEnabled('refreshContentButton').should.be.true; getDomState().should.equal('default'); }); @@ -169,7 +169,7 @@ describe('State', () => { const state = new loot.State(); state.enterEditingState(); - should.throws(() => { state.exitSortingState(); }, Error); + should.throw(() => { state.exitSortingState(); }, Error); }); it('should have no effect if already in the default state', () => { @@ -178,12 +178,12 @@ describe('State', () => { state.currentState.should.equal(loot.State.DEFAULT_STATE); - should(getShown('updateMasterlistButton')).be.undefined(); - should(getShown('sortButton')).be.undefined(); - should(getShown('applySortButton')).be.undefined(); - should(getShown('cancelSortButton')).be.undefined(); - should(getEnabled('gameMenu')).be.undefined(); - should(getEnabled('refreshContentButton')).be.undefined(); + should.equal(undefined, getShown('updateMasterlistButton')); + should.equal(undefined, getShown('sortButton')); + should.equal(undefined, getShown('applySortButton')); + should.equal(undefined, getShown('cancelSortButton')); + should.equal(undefined, getEnabled('gameMenu')); + should.equal(undefined, getEnabled('refreshContentButton')); }); }); @@ -194,13 +194,13 @@ describe('State', () => { state.currentState.should.equal(loot.State.EDITING_STATE); - getEnabled('wipeUserlistButton').should.be.false(); - getEnabled('copyContentButton').should.be.false(); - getEnabled('refreshContentButton').should.be.false(); - getEnabled('settingsButton').should.be.false(); - getEnabled('gameMenu').should.be.false(); - getEnabled('updateMasterlistButton').should.be.false(); - getEnabled('sortButton').should.be.false(); + getEnabled('wipeUserlistButton').should.be.false; + getEnabled('copyContentButton').should.be.false; + getEnabled('refreshContentButton').should.be.false; + getEnabled('settingsButton').should.be.false; + getEnabled('gameMenu').should.be.false; + getEnabled('updateMasterlistButton').should.be.false; + getEnabled('sortButton').should.be.false; getDomState().should.equal('editing'); }); @@ -209,7 +209,7 @@ describe('State', () => { const state = new loot.State(); state.enterSortingState(); - should.throws(() => { state.enterEditingState(); }, Error); + should.throw(() => { state.enterEditingState(); }, Error); }); it('should have no effect if already in the editing state', () => { @@ -219,13 +219,13 @@ describe('State', () => { state.currentState.should.equal(loot.State.EDITING_STATE); - getEnabled('wipeUserlistButton').should.be.false(); - getEnabled('copyContentButton').should.be.false(); - getEnabled('refreshContentButton').should.be.false(); - getEnabled('settingsButton').should.be.false(); - getEnabled('gameMenu').should.be.false(); - getEnabled('updateMasterlistButton').should.be.false(); - getEnabled('sortButton').should.be.false(); + getEnabled('wipeUserlistButton').should.be.false; + getEnabled('copyContentButton').should.be.false; + getEnabled('refreshContentButton').should.be.false; + getEnabled('settingsButton').should.be.false; + getEnabled('gameMenu').should.be.false; + getEnabled('updateMasterlistButton').should.be.false; + getEnabled('sortButton').should.be.false; }); }); @@ -237,13 +237,13 @@ describe('State', () => { state.currentState.should.equal(loot.State.DEFAULT_STATE); - getEnabled('wipeUserlistButton').should.be.true(); - getEnabled('copyContentButton').should.be.true(); - getEnabled('refreshContentButton').should.be.true(); - getEnabled('settingsButton').should.be.true(); - getEnabled('gameMenu').should.be.true(); - getEnabled('updateMasterlistButton').should.be.true(); - getEnabled('sortButton').should.be.true(); + getEnabled('wipeUserlistButton').should.be.true; + getEnabled('copyContentButton').should.be.true; + getEnabled('refreshContentButton').should.be.true; + getEnabled('settingsButton').should.be.true; + getEnabled('gameMenu').should.be.true; + getEnabled('updateMasterlistButton').should.be.true; + getEnabled('sortButton').should.be.true; getDomState().should.equal('default'); }); @@ -252,7 +252,7 @@ describe('State', () => { const state = new loot.State(); state.enterSortingState(); - should.throws(() => { state.exitEditingState(); }, Error); + should.throw(() => { state.exitEditingState(); }, Error); }); it('should have no effect if already in the default state', () => { @@ -261,13 +261,13 @@ describe('State', () => { state.currentState.should.equal(loot.State.DEFAULT_STATE); - should(getEnabled('wipeUserlistButton')).be.undefined(); - should(getEnabled('copyContentButton')).be.undefined(); - should(getEnabled('refreshContentButton')).be.undefined(); - should(getEnabled('settingsButton')).be.undefined(); - should(getEnabled('gameMenu')).be.undefined(); - should(getEnabled('updateMasterlistButton')).be.undefined(); - should(getEnabled('sortButton')).be.undefined(); + should.equal(undefined, getEnabled('wipeUserlistButton')); + should.equal(undefined, getEnabled('copyContentButton')); + should.equal(undefined, getEnabled('refreshContentButton')); + should.equal(undefined, getEnabled('settingsButton')); + should.equal(undefined, getEnabled('gameMenu')); + should.equal(undefined, getEnabled('updateMasterlistButton')); + should.equal(undefined, getEnabled('sortButton')); }); }); }); diff --git a/src/tests/gui/html/js/test_translator.js b/src/tests/gui/html/js/test_translator.js index ac0362b2..55533d64 100644 --- a/src/tests/gui/html/js/test_translator.js +++ b/src/tests/gui/html/js/test_translator.js @@ -17,13 +17,13 @@ describe('Translator', () => { it('should return a Promise', () => { const l10n = new loot.Translator(); - l10n.load().should.be.a.Promise(); // eslint-disable-line new-cap + l10n.load().should.be.a('promise'); // eslint-disable-line new-cap }); it('should be fulfilled for a locale of "en"', () => { const l10n = new loot.Translator('en'); - return l10n.load().should.be.fulfilled(); + return l10n.load(); }); /* Cannot test rejection or other locales as the URL uses is invalid in the diff --git a/src/tests/gui/html/js/test_updateExists.js b/src/tests/gui/html/js/test_updateExists.js index de6ebce6..42aaf006 100644 --- a/src/tests/gui/html/js/test_updateExists.js +++ b/src/tests/gui/html/js/test_updateExists.js @@ -1,39 +1,57 @@ 'use strict'; describe('updateExists()', () => { - it('should reject if no arguments are passed', () => { - return loot.updateExists().should.be.rejected(); - }); + it('should reject if no arguments are passed', () => + loot.updateExists().catch((error) => + error.should.be.an('error') + ) + ); - it('should reject if one argument is passed', () => { - return loot.updateExists('1.0.0').should.be.rejected(); - }); + it('should reject if one argument is passed', () => + loot.updateExists('1.0.0').catch((error) => + error.should.be.an('error') + ) + ); - it('should reject if passed a version number has less than three parts', () => { - return loot.updateExists('1.0', 'deadbeef').should.be.rejected(); - }); + it('should reject if passed a version number has less than three parts', () => + loot.updateExists('1.0', 'deadbeef').catch((error) => + error.should.be.an('error') + ) + ); - it('should reject if passed a version number has more than three parts', () => { - return loot.updateExists('1.0.0.0', 'deadbeef').should.be.rejected(); - }); + it('should reject if passed a version number has more than three parts', () => + loot.updateExists('1.0.0.0', 'deadbeef').catch((error) => + error.should.be.an('error') + ) + ); - it('should reject if the version number given contains non-digit, non-period characters', () => { - return loot.updateExists('1.0a.0', 'deadbeef').should.be.rejected(); - }); + it('should reject if the version number given contains non-digit, non-period characters', () => + loot.updateExists('1.0a.0', 'deadbeef').catch((error) => + error.should.be.an('error') + ) + ); - it('should resolve to true if the given version is less than the latest version', () => { - return loot.updateExists('0.9.1', 'deadbeef').should.be.fulfilledWith(true); - }); + it('should resolve to true if the given version is less than the latest version', () => + loot.updateExists('0.9.1', 'deadbeef').then((result) => + result.should.be.true + ) + ); - it('should resolve to false if the given version is greater than the latest version', () => { - return loot.updateExists('0.10.0', 'deadbeef').should.be.fulfilledWith(false); - }); + it('should resolve to false if the given version is greater than the latest version', () => + loot.updateExists('0.10.0', 'deadbeef').then((result) => + result.should.be.false + ) + ); - it('should resolve to true if the given version equals the latest version but the short build SHAs are unequal', () => { - return loot.updateExists('0.9.2', 'deadbeef').should.be.fulfilledWith(true); - }); + it('should resolve to true if the given version equals the latest version but the short build SHAs are unequal', () => + loot.updateExists('0.9.2', 'deadbeef').then((result) => + result.should.be.true + ) + ); - it('should resolve to false if the given version equals the latest version and the short build SHAs are equal', () => { - return loot.updateExists('0.9.2', '6b58f92').should.be.fulfilledWith(false); - }); + it('should resolve to false if the given version equals the latest version and the short build SHAs are equal', () => + loot.updateExists('0.9.2', '6b58f92').then((result) => + result.should.be.false + ) + ); });