expect.js

Testing Redux combined reducers

邮差的信 提交于 2019-12-09 17:07:29
问题 Say I have several reducer functions and I combine them all into one reducer using combineReducers(...) , is there a way of testing what reducers the combined reducer actually contains? For example, if I have this: import { combineReducers } from 'redux' const reducer1 = (state, action) => {...} ... (more reducers, etc) const rootReducer = combineReducers({ reducer1, reducer2, reducer3 }) export default rootReducer Can I write a test with Mocha and Expect.js that will enable me to check if

Test with reactjs renderIntoDocument keep failed due to required DOM

别来无恙 提交于 2019-12-04 09:11:00
问题 I am new to reactJS and try to learn how to test with it. I have encouter the following testing util method. However i am keep getting the same error message:ReferenceError: document is not defined . renderIntoDocument ReactComponent renderIntoDocument( ReactElement instance ) Render a component into a detached DOM node in the document. This function requires a DOM. Note: You will need to have window, window.document and window.document.createElement globally available before you import React

Testing Redux combined reducers

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:56:14
Say I have several reducer functions and I combine them all into one reducer using combineReducers(...) , is there a way of testing what reducers the combined reducer actually contains? For example, if I have this: import { combineReducers } from 'redux' const reducer1 = (state, action) => {...} ... (more reducers, etc) const rootReducer = combineReducers({ reducer1, reducer2, reducer3 }) export default rootReducer Can I write a test with Mocha and Expect.js that will enable me to check if the rootReducer contains say reducer2 ? Is this even possible? The way I currently have my project set up

Re-throwing exception in NodeJS and not losing stack trace

谁说胖子不能爱 提交于 2019-12-03 08:11:42
问题 How can I rethrow an error or exception in nodejs/javascript and include a custom message. I have the following code var json = JSON.parse(result); and I wanted to include the result content in the exception message should any parsing error occurs. Something like this. 1. try { 2. var json = JSON.parse(result); 3. expect(json.messages.length).to.be(1); 4. } catch(ex) { 5. throw new Error(ex.message + ". " + "JSON response: " + result); 6. } The problem here is that I lose my stack trace. Is

Re-throwing exception in NodeJS and not losing stack trace

夙愿已清 提交于 2019-12-03 02:07:12
How can I rethrow an error or exception in nodejs/javascript and include a custom message. I have the following code var json = JSON.parse(result); and I wanted to include the result content in the exception message should any parsing error occurs. Something like this. 1. try { 2. var json = JSON.parse(result); 3. expect(json.messages.length).to.be(1); 4. } catch(ex) { 5. throw new Error(ex.message + ". " + "JSON response: " + result); 6. } The problem here is that I lose my stack trace. Is there a way to do it similar to java ? throw new Error("JSON response: " + result, ex); I'm not aware of