You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shimmed.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var trimLeft = require('../');
  3. trimLeft.shim();
  4. var runTests = require('./tests');
  5. var test = require('tape');
  6. var defineProperties = require('define-properties');
  7. var callBind = require('es-abstract/helpers/callBind');
  8. var isEnumerable = Object.prototype.propertyIsEnumerable;
  9. var functionsHaveNames = require('functions-have-names')();
  10. test('shimmed', function (t) {
  11. t.equal(String.prototype.trimLeft.length, 0, 'String#trimLeft has a length of 0');
  12. t.test('Function name', { skip: !functionsHaveNames }, function (st) {
  13. st.equal((/^(?:trimLeft|trimStart)$/).test(String.prototype.trimLeft.name), true, 'String#trimLeft has name "trimLeft" or "trimStart"');
  14. st.end();
  15. });
  16. t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
  17. et.equal(false, isEnumerable.call(String.prototype, 'trimLeft'), 'String#trimLeft is not enumerable');
  18. et.end();
  19. });
  20. var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
  21. t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
  22. st['throws'](function () { return trimLeft(undefined, 'a'); }, TypeError, 'undefined is not an object');
  23. st['throws'](function () { return trimLeft(null, 'a'); }, TypeError, 'null is not an object');
  24. st.end();
  25. });
  26. runTests(callBind(String.prototype.trimLeft), t);
  27. t.end();
  28. });