source: node_modules/object-inspect/test/toStringTag.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var test = require('tape');
4var hasToStringTag = require('has-tostringtag/shams')();
5
6var inspect = require('../');
7
8test('Symbol.toStringTag', { skip: !hasToStringTag }, function (t) {
9 t.plan(4);
10
11 var obj = { a: 1 };
12 t.equal(inspect(obj), '{ a: 1 }', 'object, no Symbol.toStringTag');
13
14 obj[Symbol.toStringTag] = 'foo';
15 t.equal(inspect(obj), '{ a: 1, [Symbol(Symbol.toStringTag)]: \'foo\' }', 'object with Symbol.toStringTag');
16
17 t.test('null objects', { skip: 'toString' in { __proto__: null } }, function (st) {
18 st.plan(2);
19
20 var dict = { __proto__: null, a: 1 };
21 st.equal(inspect(dict), '[Object: null prototype] { a: 1 }', 'null object with Symbol.toStringTag');
22
23 dict[Symbol.toStringTag] = 'Dict';
24 st.equal(inspect(dict), '[Dict: null prototype] { a: 1, [Symbol(Symbol.toStringTag)]: \'Dict\' }', 'null object with Symbol.toStringTag');
25 });
26
27 t.test('instances', function (st) {
28 st.plan(4);
29
30 function C() {
31 this.a = 1;
32 }
33 st.equal(Object.prototype.toString.call(new C()), '[object Object]', 'instance, no toStringTag, Object.prototype.toString');
34 st.equal(inspect(new C()), 'C { a: 1 }', 'instance, no toStringTag');
35
36 C.prototype[Symbol.toStringTag] = 'Class!';
37 st.equal(Object.prototype.toString.call(new C()), '[object Class!]', 'instance, with toStringTag, Object.prototype.toString');
38 st.equal(inspect(new C()), 'C [Class!] { a: 1 }', 'instance, with toStringTag');
39 });
40});
Note: See TracBrowser for help on using the repository browser.