-
Notifications
You must be signed in to change notification settings - Fork 3
feat(tests): Next reaclette tests #30
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
feat(tests): Next reaclette tests #30
Conversation
ece1d9b
to
6f6a9ca
Compare
src/new.spec.js
Outdated
|
||
expect(getRenderArgs()[0]).toHaveProperty("effects"); | ||
expect(getRenderArgs()[0]).toHaveProperty("resetState"); | ||
expect(getRenderArgs()[0]).toHaveProperty("state"); |
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.
What do you think about this?
const isReadOnly = object =>
!Object.isExtensible(object) &&
Object.getOwnPropertyNames(object).every(name => {
const descriptor = Object.getOwnPropertyDescriptor(object, name)
return (
!descriptor.configurable &&
(descriptor.set === undefined || !descriptor.writable)
)
})
const store = getRenderArgs()[0]
assert(isReadOnly(store))
const { effects, resetState, state } = store
assert(isReadOnly(effects))
expect(Object.getOwnPropertyNames(effects)).toEqual(['_setState', 'myEffect'])
expect(typeof resetState).toBe('function')
assert(isReadOnly(state))
expect(Object.getOwnPropertyNames(state)).toEqual(['myEntry'])
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.
I see that this is very precise. but it's not related with what was the described in the test: receives the store as first param with effects, state and resetState
I will add what you wrote in a new test
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.
What I described was just a list of ideas of what to test.
Feel free to add, merge and split as necessary.
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.
const isReadOnly = object =>
!Object.isExtensible(object) &&
Object.getOwnPropertyDescriptors(object).every(
_ => _.set === undefined || _.writable === false
)
Every
works only with arrays and not with objects
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.
You're right, you should use Object.keys()
with Object.getOwnPropertyDescriptor()
then.
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.
isReadOnly
should be like this:
const isReadOnly = object =>
!Object.isExtensible(object) &&
Object.values(Object.getOwnPropertyDescriptors(object)).every(
_ => _.set === undefined || _.writable === false
);
and Object.keys(effects)
will always be []
(empty) because nothing is enumerable
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.
46:3 error Object.values() is not supported in IE 11 compat/compat
46:3 error The 'Object.values' is not supported until Node.js 7.0.0. The configured version range is '>=6' node/no-unsupported-features/es-builtins
46:17 error The 'Object.getOwnPropertyDescriptors' is not supported until Node.js 7.0.0. The configured version range is '>=6' node/no-unsupported-features/es-builtins
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.
You're right for Object.keys
, I should have said Object.getOwnPropertyNames
.
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.
Easier solution is to use Object.getOwnPropertyNames
and Object.getOwnPropertyDescriptor
.
src/new.spec.js
Outdated
|
||
describe("withStore", () => { | ||
describe("render function", () => { | ||
it("returns readOnly state, effects, props and resetState func", async () => { |
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.
Nope.
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.
!
No description provided.