class-name.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. /* eslint-disable no-empty-function */
  3. var assert = require("@sinonjs/referee").assert;
  4. var className = require("./class-name");
  5. describe("className", function() {
  6. it("returns the class name of an instance", function() {
  7. // Because eslint-config-sinon disables es6, we can't
  8. // use a class definition here
  9. // https://github.com/sinonjs/eslint-config-sinon/blob/master/index.js
  10. // var instance = new (class TestClass {})();
  11. var instance = new function TestClass() {}();
  12. var name = className(instance);
  13. assert.equals(name, "TestClass");
  14. });
  15. it("returns 'Object' for {}", function() {
  16. var name = className({});
  17. assert.equals(name, "Object");
  18. });
  19. it("returns null for an object that has no prototype", function() {
  20. var obj = Object.create(null);
  21. var name = className(obj);
  22. assert.equals(name, null);
  23. });
  24. it("returns null for an object whose prototype was mangled", function() {
  25. // This is what Node v6 and v7 do for objects returned by querystring.parse()
  26. function MangledObject() {}
  27. MangledObject.prototype = Object.create(null);
  28. var obj = new MangledObject();
  29. var name = className(obj);
  30. assert.equals(name, null);
  31. });
  32. });