似乎无法用 Jest 进行测试,因为我正在使用样式组件。有人找到解决这个问题的方法吗?
\n\n我将我的“StyledComponents.js”组件放在一个单独的文件中,并根据需要将它们导入到我的页面中..ala。
\n\n从“StyledComponents”导入{页脚、页眉、LeftNav};
\n\n PASS src/app/components/Products/__tests__/Avatar.test.js\n FAIL src/app/components/Products/__tests__/product-snapshot-test.js\n \xe2\x97\x8f Test suite failed to run\n\n TypeError: Cannot read property \'div\' of undefined\n\n\n at Object.<anonymous> (src/app/components/Products/styledComponents.js:9:148)\n at Object.<anonymous> (src/app/components/Products/ProductsItem.js:3:41)\n at Object.<anonymous> (src/app/components/Products/index.js:7:50)\n at Object.<anonymous> (src/app/components/Products/__tests__/product-snapshot-test.js:5:14)\nRun Code Online (Sandbox Code Playgroud)\n\n包含来自 styled.js 文件(ala:styled-components)的组件的导入文件部分令人窒息。
\n\n// @flow\nimport React from \'react\';\nimport {\n Products,\n ProductItem\n} from \'./styledComponents\';\nRun Code Online (Sandbox Code Playgroud)\n\n基本上,它说“样式”是未定义的。然而,在我的文件中,我有:
\n\nimport styled from \'styled-components\';\n\nexport const ProductContainer = styled.div`\n border-radius: 5px;\n overflow: hidden;\n`;\n\netc.... \nRun Code Online (Sandbox Code Playgroud)\n\n更新为包括 babelrc 和 package.json 文件
\n\n巴贝尔库
\n\n{\n "presets": ["es2015", …Run Code Online (Sandbox Code Playgroud) 如果你让我获得阵列的最大值,我会这样做:
var nums = [66,3,8,213,965,1,453];
Math.max.apply(Math, nums);
Run Code Online (Sandbox Code Playgroud)
当然,我也可以这样做:nums.sort(功能(A,B){返回 - B} .pop(nums.length);
但我必须诚实.我需要知道为什么有效 - 使用.apply(数学,数字).如果我这样做:
Math.max(nums);
Run Code Online (Sandbox Code Playgroud)
那不行.
通过使用apply,我传入Math作为这个 - 以及数组的nums.但我想知道第一个有效的"为什么"的复杂性,后者却没有.发生了什么魔法?
有一些基本的东西,我没有缠绕我的大脑.我读了很多关于"打电话和申请"的内容,但很多时候可以像上面那样有一些很酷的技巧,而且我觉得我在这里缺少更深层次的东西.
我正在赛普拉斯创建一些集成测试。
我目前的注册流程已经关闭。-这是一个文件测试。
registration.spec.js
现在,我想运行一个login.spec.js测试。如何使用在registration.spec.js中创建的动态电子邮件,并在“ login.spec.js”中使用该电子邮件?
registration.spec.js
----> create a dynamic email address
----> do some tests
----> end registration test
login.spec.js
---> login with email/pw I created in the registration.spec.js file?
Run Code Online (Sandbox Code Playgroud)
这是如何实现的。柏树中是否有injectGlobal类型的交易?
另外,如果我以独立方式运行login.spec.js,是否可以使用“提供的”凭据或通过全局参数保存的凭据来运行所有测试?那有意义吗?
我想运行所有测试...
registration.spec.js (create dynamic email/pw)
login.spec.js (use dynamic values from registration process)
or
login.spec.js (standalone, use supplied credentials)
Run Code Online (Sandbox Code Playgroud) 我正在使用 Helmet.contentSecurityPolicy,这里是我的对象的要点:
我的脚本没有加载......这没有加载,但你可以看到我在我的信任项目中拥有它;
未加载:这些是通过 GOOGLETAGMANGER 加载的项目,但我有一个随机数?

并且在其中一些的脚本标签中,比如 googleTagmanager,我添加了 nonce .. 现在,对于一些,我无法添加,但我将它们明确地放在配置中。
example of nonce in script tag:
<script nonce="2d4f393ea5bc957db4f385232a53fcc8" async src="https://www.googletagmanager.com/gtag/js?id=*******"></script>
Run Code Online (Sandbox Code Playgroud)
那些 本地主机这些是由 webpack 创建的,但我的可接受项目中显然有“本地主机”......所以我很困惑。有什么帮助吗?
The errors, are like the following: But I do HAVE the nonce tag (in some of them) AND you can see I include "unsafe-inline".
Refused to load the script '<URL>' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'unsafe-inline' nonce-a449a007188e909846c2e74148c3e1b0 <URL> *.kustomerapp.com/ <URL> *.segment.com/ <URL> *.cloudfront.net <URL> *.stripe.com <URL> *.split.io <URL> *.googletagmanager.com …Run Code Online (Sandbox Code Playgroud) 我以前从未遇到过这个问题...但现在它给了我...
// TS7022: 'rootReducer' implicitly has type 'any' because it does not
// have a type annotation and is referenced directly or indirectly in its own initializer
const rootReducer = combineReducers({
employee: employee.reducer,
company: company.reducer,
alerts: alerts.reducer,
});
// gives error: TS2456: Type alias 'RootState' circularly references itself.
export type RootState = ReturnType<typeof rootReducer>;
function makeStore() {
return configureStore(
{
reducer: rootReducer,
devTools: true,
})
}
Run Code Online (Sandbox Code Playgroud) 在查看缩小的Sizzle代码时,我注意到它的开头是这样的:
!function(a){//...
}(window)
Run Code Online (Sandbox Code Playgroud)
为什么一开始就有感叹号?
我以为那!是not运营商.
谢谢.
编辑:
完整代码.
所以,我正在深入研究Java并对这种类型参数的使用感到好奇.
<T>T getInstance
Run Code Online (Sandbox Code Playgroud)
然后是arg
Class<T> type
Run Code Online (Sandbox Code Playgroud)
我在这里有点困惑因为如果我们需要一个返回类型,因此用T表示那么为什么arg不一样...例如
private static String getInstance(String arg)
Run Code Online (Sandbox Code Playgroud)
所以我想它会是
private static Class<T> getInstance(final Class<T> type)
Run Code Online (Sandbox Code Playgroud)
所以,我很困惑为什么返回类型与参数的表达式有所不同
我正在从我的 API 取回发票,并且我注意到如果有 2 个整月的计费周期,一切都很好 - 但我总是得到一个开始/结束日期和创建日期相同的发票。
所以,我最终显示它并且它没有意义......即。
假设用户在 2016 年 7 月 19 日创建了一个帐户......对于其中一张发票(其他发票很好),我得到了这个。
amount: 0
billingDate:"2016-07-19T23:20:33.000Z"
endDate:"2016-07-19T23:20:33.000Z"
startDate:"2016-07-19T23:20:33.000Z"
Run Code Online (Sandbox Code Playgroud)
我应该如何处理这个问题,或者这是一个有效的回应?请记住,我的帐单是在 8 号。我只是有点害怕:-),如果开始/结束/创建日期都相同,则省略它。
所以,我有以下代码,但流程错误不断弹出。我试过投射 Object.entries,但不起作用 - 其他东西。任何见解?
type Fields = {
name: string,
func: (*) => boolean
};
type S = {
key1: Fields,
bill: Fields
}
var a: S = {
key1: {name: 'mary', func: (str) => str === 'mary'},
bill: {name: 'bill', func: (str) => str === 'bill'}
}
var c = Object
.entries(a)
.map(([key, obj]) => obj.func(key) ? obj : false)
.filter(f => f)
.reduce((acc, c) => {
return 'something here'
}, {});
Run Code Online (Sandbox Code Playgroud)
我已经省略了一些东西,但速度是一样的。Flow 正在读取这些条目作为返回元组类型。我尝试了各种各样的事情,但我没有把事情搞砸,而是保持原样。
我似乎无法在这里注释解构的项目 ([key, obj]),得到元组错误...
将代码分配给 var …
因此,我在 onSuccess 中有一些辅助行为,例如分析等。我需要传递到跟踪,不仅是查询/突变的结果(在本例中是突变),还需要传递我传入的参数。似乎只有将其附加到返回“数据”时我才能做到这一点?
export default function useProductToWishList () {
const queryClient = useQueryClient();
return useMutation(
async ({ product, email }) => {
const data = await product.addWishList({ product, email });
if (data.status === 500 || data.err) throw new Error(data.err);
return data;
},
{
onSuccess:(data) => {
const { product: response = {} } = data?.data ?? {};
queryClient.setQueryData(['products'], {...response });
analytics(response, email); // HERE. How can I get at email?
}
}
)
}
Run Code Online (Sandbox Code Playgroud)
当我不需要它来响应但需要副作用时,这样做似乎很奇怪。有什么想法吗?
return { ...data, email }
Run Code Online (Sandbox Code Playgroud) javascript ×2
babel-jest ×1
class ×1
cypress ×1
express ×1
flowtype ×1
function ×1
generics ×1
helmet.js ×1
java ×1
jestjs ×1
react-query ×1
reactjs ×1
sizzle ×1