test_classnames.js (1388B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests utility function in `classnames.js` 8 */ 9 10 const classnames = require("resource://devtools/client/shared/classnames.js"); 11 12 add_task(async function () { 13 Assert.equal( 14 classnames(), 15 "", 16 "Returns an empty string when called with no params" 17 ); 18 Assert.equal( 19 classnames(null, undefined, false), 20 "", 21 "Returns an empty string when called with only falsy params" 22 ); 23 Assert.equal( 24 classnames("hello"), 25 "hello", 26 "Returns expected result when string is passed" 27 ); 28 Assert.equal( 29 classnames("hello", "", "world"), 30 "hello world", 31 "Doesn't add extra spaces for empty strings" 32 ); 33 Assert.equal( 34 classnames("hello", null, undefined, false, "world"), 35 "hello world", 36 "Doesn't add extra spaces for falsy values" 37 ); 38 Assert.equal( 39 classnames("hello", { nice: true, blue: 42, world: {} }), 40 "hello nice blue world", 41 "Add property key when property value is truthy" 42 ); 43 Assert.equal( 44 classnames("hello", { nice: false, blue: null, world: false }), 45 "hello", 46 "Does not add property key when property value is falsy" 47 ); 48 Assert.equal( 49 classnames("hello", { nice: true }, { blue: true }, "world"), 50 "hello nice blue world", 51 "Handles multiple objects" 52 ); 53 });