Skip to content

Commit

Permalink
Run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Jan 19, 2022
1 parent 12a4593 commit fb8b3d7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
21 changes: 16 additions & 5 deletions lib/sinon/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,33 @@ stub.createStubInstance = function (constructor, overrides) {
};

function assertValidPropertyDescriptor(descriptor, property) {
if (!descriptor || !property) {
if (!descriptor || !property) {
return;
}
if (!descriptor.configurable && !descriptor.writable) {
throw new TypeError(`Descriptor for property ${property} is non-configurable and non-writable`);
throw new TypeError(
`Descriptor for property ${property} is non-configurable and non-writable`
);
}
if ((descriptor.get || descriptor.set) && !descriptor.configurable) {
throw new TypeError(`Descriptor for accessor property ${property} is non-configurable`);
throw new TypeError(
`Descriptor for accessor property ${property} is non-configurable`
);
}
if (isDataDescriptor(descriptor) && !descriptor.writable) {
throw new TypeError(`Descriptor for data property ${property} is non-writable`);
throw new TypeError(
`Descriptor for data property ${property} is non-writable`
);
}
}

function isDataDescriptor(descriptor) {
return !descriptor.value && !descriptor.writable && !descriptor.set && !descriptor.get;
return (
!descriptor.value &&
!descriptor.writable &&
!descriptor.set &&
!descriptor.get
);
}

/*eslint-disable no-use-before-define*/
Expand Down
40 changes: 20 additions & 20 deletions test/shared-spy-stub-everything-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,48 +154,48 @@ module.exports = function shared(createSpyOrStub) {

it("throws on data property descriptors that are not writable or configurable", function () {
var myObj = {};
Object.defineProperty(myObj, 'ignoreme', {
Object.defineProperty(myObj, "ignoreme", {
writable: false,
configurable: false
configurable: false,
});

assert.exception(function () {
createSpyOrStub(myObj, "ignoreme");
},
new TypeError('Descriptor for property ignoreme is non-configurable and non-writable')
);
createSpyOrStub(myObj, "ignoreme");
}, new TypeError(
"Descriptor for property ignoreme is non-configurable and non-writable"
));
});

it("throws on accessor property descriptors that are not configurable", function () {
var myObj = {};
Object.defineProperty(myObj, 'ignoreme', {
get: function(key) {
Object.defineProperty(myObj, "ignoreme", {
get: function (key) {
return this[key];
},
set: function(key, val) {
set: function (key, val) {
this[key] = val;
},
configurable: false
configurable: false,
});

assert.exception(function () {
createSpyOrStub(myObj, "ignoreme");
},
new TypeError('Descriptor for accessor property ignoreme is non-configurable')
);
createSpyOrStub(myObj, "ignoreme");
}, new TypeError(
"Descriptor for accessor property ignoreme is non-configurable"
));
});

it("throws on data descriptors that are not stubbable", function () {
var myObj = {};
Object.defineProperty(myObj, 'ignoreme', {
Object.defineProperty(myObj, "ignoreme", {
writable: false,
configurable: false
configurable: false,
});

assert.exception(function () {
createSpyOrStub(myObj, "ignoreme");
},
new TypeError('Descriptor for data property ignoreme is non-writable')
);
createSpyOrStub(myObj, "ignoreme");
}, new TypeError(
"Descriptor for data property ignoreme is non-writable"
));
});
};

0 comments on commit fb8b3d7

Please sign in to comment.