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.
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.
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.
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.
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.
You're right, you should use Object.keys() with Object.getOwnPropertyDescriptor() then.
There was a problem hiding this comment.
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.
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-builtinsThere was a problem hiding this comment.
You're right for Object.keys, I should have said Object.getOwnPropertyNames.
There was a problem hiding this comment.
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 () => { |
No description provided.