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