-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Tests for issue #20 #21
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,4 +271,41 @@ describe('ReadOnlyHandler', () => { | |
doNothing(readOnly.foo); | ||
}).not.toThrow(); | ||
}); | ||
|
||
describe.skip('issue#20 - getOwnPropertyDescriptor', () => { | ||
it('should return reactive proxy when property accessed via raw getter', () => { | ||
const target = new ReactiveMembrane(); | ||
const todos = {}; | ||
Object.defineProperty(todos, 'entry', { | ||
get() { | ||
return { foo: 'bar' }; | ||
}, | ||
configurable: true | ||
}); | ||
|
||
const proxy = target.getReadOnlyProxy(todos); | ||
const desc = Object.getOwnPropertyDescriptor(proxy, 'entry'); | ||
const { get } = desc; | ||
expect(() => { | ||
get().foo = ''; | ||
}).toThrow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps this should become a test of its own? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second assertion(L292) is verifying that the data wasn't mutated. To separate it to its own test case I would have to copy the whole thing, place the mutation attempt(L290) in a try-catch. Seems too much duplication for asserting that read only proxy is blocking the mutation. And I have the test case description wrong, will fix that. |
||
expect(todos['entry'].foo).toEqual('bar'); | ||
}); | ||
it('should return reactive proxy when property accessed via descriptor', () => { | ||
const target = new ReactiveMembrane(); | ||
const todos = {}; | ||
Object.defineProperty(todos, 'entry', { | ||
value : { foo: 'bar' }, | ||
configurable: true | ||
}); | ||
|
||
const proxy = target.getReadOnlyProxy(todos); | ||
const desc = Object.getOwnPropertyDescriptor(proxy, 'entry'); | ||
const { value } = desc; | ||
expect( () => { | ||
value.foo = ''; | ||
}).toThrow(); | ||
expect(todos['entry'].foo).toEqual('bar'); | ||
}); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aside from assertion to throw, what is the difference between the tests in this file and reactive-handler.spec.ts? Wondering if we are duplicating here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are testing two different APIs. Test cases in reactive-handler.spec.ts is testing that the inner object is wrapped in a reactive proxy. The test cases in this file is testing that the readonly proxy cannot be bypassed. The testcase name is wrong. Will fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both the tests exploit the same loop hole in the implementation. |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 51 does the opposite of the original comment.