mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
zjquery: Use Proxy to detect undefined stubs.
We now use a Proxy to wrap zjquery elements, so that we can detect callers trying to invoke methods (or access attributes) that do not exist. We try to give useful error messages in those cases. The main impact here is that we force lots of tests to explicitly stub `length`. Also, we can't do equality checks on zjquery objects any more due to the proxy object, but the easy workaround is to compare selectors. (This is generally an unnecessary technique, anyway.) The proxy wrapper is fairly straightforward, and we just have a few special cases for things like "inspect" that happen when you try to print out objects.
This commit is contained in:
@@ -74,9 +74,8 @@ the stub for a function you're calling in your patch. Typically the stub
|
||||
is just placed in the test file, to prevent bloating of `zjquery`
|
||||
with functions that are only used in a single test.
|
||||
|
||||
A good sign that you need to stub something out is getting an error of
|
||||
the type:
|
||||
`TypeError: <component>.<method> is not a function`
|
||||
If you need to stub, you will see an error of this form:
|
||||
`Error: You must create a stub for $("#foo").bar`
|
||||
|
||||
The `zjquery` library itself is only about 500 lines of code, and can
|
||||
also be a useful resource if you're having trouble debugging DOM
|
||||
|
||||
Reference in New Issue
Block a user