2
0

s-object.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. describe('Object', function () {
  2. "use strict";
  3. describe("Object.keys", function () {
  4. var obj = {
  5. "str": "boz",
  6. "obj": { },
  7. "arr": [],
  8. "bool": true,
  9. "num": 42,
  10. "null": null,
  11. "undefined": undefined
  12. };
  13. var loopedValues = [];
  14. for (var k in obj) {
  15. loopedValues.push(k);
  16. }
  17. var keys = Object.keys(obj);
  18. it('should have correct length', function () {
  19. expect(keys.length).toBe(7);
  20. });
  21. it('should return an Array', function () {
  22. expect(Array.isArray(keys)).toBe(true);
  23. });
  24. it('should return names which are own properties', function () {
  25. keys.forEach(function (name) {
  26. expect(obj.hasOwnProperty(name)).toBe(true);
  27. });
  28. });
  29. it('should return names which are enumerable', function () {
  30. keys.forEach(function (name) {
  31. expect(loopedValues.indexOf(name)).toNotBe(-1);
  32. })
  33. });
  34. it('should throw error for non object', function () {
  35. var e = {};
  36. expect(function () {
  37. try {
  38. Object.keys(42)
  39. } catch (err) {
  40. throw e;
  41. }
  42. }).toThrow(e);
  43. });
  44. });
  45. describe("Object.isExtensible", function () {
  46. var obj = { };
  47. it('should return true if object is extensible', function () {
  48. expect(Object.isExtensible(obj)).toBe(true);
  49. });
  50. it('should return false if object is not extensible', function () {
  51. expect(Object.isExtensible(Object.preventExtensions(obj))).toBe(false);
  52. });
  53. it('should return false if object is seal', function () {
  54. expect(Object.isExtensible(Object.seal(obj))).toBe(false);
  55. });
  56. it('should return false if object is freeze', function () {
  57. expect(Object.isExtensible(Object.freeze(obj))).toBe(false);
  58. });
  59. it('should throw error for non object', function () {
  60. var e1 = {};
  61. expect(function () {
  62. try {
  63. Object.isExtensible(42)
  64. } catch (err) {
  65. throw e1;
  66. }
  67. }).toThrow(e1);
  68. });
  69. });
  70. });