expect...toEqual check for Symbols

This commit is contained in:
leoni laetitia
2021-01-31 22:32:58 +01:00
parent 1320b0614f
commit 3234d475cd
6 changed files with 108 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2020 Pivotal Labs
Copyright (c) 2008-2021 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2020 Pivotal Labs
Copyright (c) 2008-2021 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2020 Pivotal Labs
Copyright (c) 2008-2021 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -5172,16 +5172,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
};
function keys(obj, isArray) {
var allKeys = Object.keys
? Object.keys(obj)
: (function(o) {
var allKeys = (function(o) {
var keys = [];
for (var key in o) {
if (j$.util.has(o, key)) {
keys.push(key);
}
}
return keys;
// eslint-disable-next-line compat/compat
return keys.concat(Object.getOwnPropertySymbols(o));
})(obj);
if (!isArray) {

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2020 Pivotal Labs
Copyright (c) 2008-2021 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('toEqual', function() {
'use strict';
@@ -1077,4 +1078,94 @@ describe('toEqual', function() {
expect(compareEquals(actual, expected).message).toEqual(message);
});
});
// == Symbols ==
describe('Symbols', function() {
it('Fails if Symbol compared to Object', function() {
var sym = Symbol('foo');
var obj = {};
expect(sym).not.toEqual(obj);
});
it('Passes Symbol with itself', function() {
var sym = Symbol('foo');
expect(sym).toEqual(sym);
});
it('Fails if two Symbols with same value are compared', function() {
var symA = Symbol('foo');
var symB = Symbol('foo');
expect(symA).not.toEqual(symB);
});
it('Fails if two Symbols with different value are compared', function() {
var symA = Symbol('foo');
var symB = Symbol('bar');
expect(symA).not.toEqual(symB);
});
it('Fails if Symbol compared to NaN', function() {
var sym = Symbol('foo');
expect(sym).not.toEqual(NaN);
});
it('Fails if Symbol compared to Infinity', function() {
var sym = Symbol('foo');
expect(sym).not.toEqual(Infinity);
});
it('Fails if Symbol compared to String', function() {
var sym = Symbol('foo');
var str = 'foo';
expect(sym).not.toEqual(str);
});
it('Fails if Symbol compared to Number', function() {
var sym = Symbol('foo');
var num = Math.random();
expect(sym).not.toEqual(num);
});
it('Fails if Symbol compared to Boolean', function() {
var sym = Symbol('foo');
expect(sym).not.toEqual(true);
expect(sym).not.toEqual(false);
});
it('Fails if Symbol compared to Undefined', function() {
var sym = Symbol('foo');
expect(sym).not.toEqual(undefined);
});
it('Fails if Symbol compared to null', function() {
var sym = Symbol('foo');
expect(sym).not.toEqual(null);
});
it('Fails if Symbol compared to []', function() {
var sym = Symbol('foo');
var arr = ['foo'];
expect(sym).not.toEqual(arr);
});
it('Fails if Symbol compared to Function', function() {
var sym = Symbol('foo');
var f = function func() {};
expect(sym).not.toEqual(f);
});
});
});

View File

@@ -544,17 +544,16 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
};
function keys(obj, isArray) {
var allKeys = Object.keys
? Object.keys(obj)
: (function(o) {
var keys = [];
for (var key in o) {
if (j$.util.has(o, key)) {
keys.push(key);
}
}
return keys;
})(obj);
var allKeys = (function(o) {
var keys = [];
for (var key in o) {
if (j$.util.has(o, key)) {
keys.push(key);
}
}
// eslint-disable-next-line compat/compat
return keys.concat(Object.getOwnPropertySymbols(o));
})(obj);
if (!isArray) {
return allKeys;