tests_funky.js 997 B

1234567891011121314151617181920212223242526272829303132
  1. (function (root, factory) {
  2. 'use strict';
  3. if (typeof module === 'object' && module.exports) {
  4. // Node. Does not work with strict CommonJS, but only CommonJS-like
  5. // environments that support module.exports, like Node.
  6. factory(require('./x2js'), require('qunit-cli'));
  7. } else {
  8. // Browser globals (root is window)
  9. factory(root.X2JS, root.QUnit);
  10. }
  11. })(this, function (X2JS, QUnit) {
  12. 'use strict';
  13. QUnit.module('Funky tests');
  14. QUnit.test('asArray() converts to array', function (assert) {
  15. var x = new X2JS();
  16. // It preserves existing arrays.
  17. assert.propEqual(x.asArray([1, 2, 3]), [1, 2, 3]);
  18. // And converts anything else.
  19. assert.propEqual(x.asArray('stringvalue'), ['stringvalue']);
  20. assert.propEqual(x.asArray({}), [{}]);
  21. assert.propEqual(x.asArray(''), ['']);
  22. // Except some things, which are turned into empty arrays just because.
  23. assert.propEqual(x.asArray(null), []);
  24. assert.propEqual(x.asArray(undefined), []);
  25. });
  26. });