Skip to content

Commit

Permalink
[Tests] use mock-property
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 16, 2022
1 parent 5af978f commit 94e83a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -62,6 +62,7 @@
"evalmd": "^0.0.19",
"foreach": "^2.0.5",
"functions-have-names": "^1.2.2",
"mock-property": "^1.0.0",
"nyc": "^10.3.2",
"object-inspect": "^1.12.0",
"object.assign": "^4.1.2",
Expand Down
17 changes: 6 additions & 11 deletions test/shimmed.js
Expand Up @@ -8,6 +8,8 @@ var test = require('tape');
var defineProperties = require('define-properties');
var callBind = require('call-bind');
var hasSymbols = require('has-symbols')();
var mockProperty = require('mock-property');

var regexMatchAll = require('../regexp-matchall');

var isEnumerable = Object.prototype.propertyIsEnumerable;
Expand Down Expand Up @@ -43,23 +45,16 @@ test('shimmed', function (t) {
});

st.test('no symbol present', function (s2t) {
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, Symbol.matchAll);

s2t.doesNotThrow(function () { 'abc'.matchAll('b'); }, 'does not throw on string input, with the symbol on regex prototype');

// eslint-disable-next-line no-extend-native
Object.defineProperty(RegExp.prototype, Symbol.matchAll, {
configurable: true,
enumerable: false,
s2t.teardown(mockProperty(RegExp.prototype, Symbol.matchAll, {
nonEnumerable: true,
value: undefined,
writable: true
});
nonWritable: false
}));

s2t['throws'](function () { 'abc'.matchAll('b'); }, 'throws on string input, without the symbol on regex prototype');

// eslint-disable-next-line no-extend-native
Object.defineProperty(RegExp.prototype, Symbol.matchAll, desc);

s2t.end();
});

Expand Down

0 comments on commit 94e83a3

Please sign in to comment.