mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Fix: Handle non-configurable properties in instrumenter for expect.toThrow
This commit is contained in:
parent
54c6d58cad
commit
039ca1a733
@ -101,7 +101,7 @@ export const WithLoaders = {
|
||||
},
|
||||
};
|
||||
|
||||
const UserEventSetup = {
|
||||
export const UserEventSetup = {
|
||||
play: async (context) => {
|
||||
const { args, canvasElement, step, userEvent } = context;
|
||||
const canvas = within(canvasElement);
|
||||
@ -132,4 +132,28 @@ const UserEventSetup = {
|
||||
},
|
||||
};
|
||||
|
||||
export { UserEventSetup };
|
||||
/**
|
||||
* Demonstrates the expect.toThrow functionality from issue #28406
|
||||
* https://github.com/storybookjs/storybook/issues/28406
|
||||
*
|
||||
* This tests various forms of throw assertions to ensure they all work correctly.
|
||||
*/
|
||||
export const ToThrow = {
|
||||
play: async () => {
|
||||
await expect(() => {
|
||||
throw new Error('test error');
|
||||
}).toThrow();
|
||||
|
||||
await expect(() => {
|
||||
throw new Error('specific error');
|
||||
}).toThrowError();
|
||||
|
||||
await expect(() => {
|
||||
throw new Error('specific message');
|
||||
}).toThrow('specific message');
|
||||
|
||||
await expect(() => {
|
||||
// This doesn't throw
|
||||
}).not.toThrow();
|
||||
},
|
||||
};
|
||||
|
@ -355,12 +355,14 @@ export class Instrumenter {
|
||||
(acc, key) => {
|
||||
const descriptor = getPropertyDescriptor(obj, key);
|
||||
if (typeof descriptor?.get === 'function') {
|
||||
const getter = () => descriptor?.get?.bind(obj)?.();
|
||||
Object.defineProperty(acc, key, {
|
||||
get: () => {
|
||||
return this.instrument(getter(), { ...options, path: path.concat(key) }, depth);
|
||||
},
|
||||
});
|
||||
if (descriptor.configurable) {
|
||||
const getter = () => descriptor?.get?.bind(obj)?.();
|
||||
Object.defineProperty(acc, key, {
|
||||
get: () => {
|
||||
return this.instrument(getter(), { ...options, path: path.concat(key) }, depth);
|
||||
},
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user