我一生都无法让 Jest/Enzyme 与样式化组件完美搭配。
我有一个我正在安装的组件,它过滤掉了最近发货的 5 个列表。
it("should have five shipments", () => {
const wrapper = shallow(<LastFiveShipments shipments={dummyProps.shipments} />);
wrapper.debug();
const styledList = wrapper.find("styled.ul");
expect(styledList).exists().to.equal(true);;
})
Run Code Online (Sandbox Code Playgroud)
const LastFiveShipments = ({shipments}) => {
return (
<StyledList>
<h5>Last Five Shipments:</h5>
{
shipments.sort((a, b) => new Date(a.cargo_units[0].created_at) - new Date(b.cargo_units[0].created_at))
.filter((shipment, index) => index < 5)
.map((shipment, index) => <li key={index}>{shipment.reference}</li> )
}
</StyledList>
)
}
const StyledList = styled.ul`
padding: 1em;
margin: 0 10px;
background: #f0f0f0;
border-radius: 10px;
border: 1px solid #14374e; …
Run Code Online (Sandbox Code Playgroud) 我们正在更新API,Babel的Henry Zhu提醒我注意此预设,babel-preset-env
以替换babel-preset-es2015
and的需要babel-preset-es2018
。
现在,我在理解最简单的方式来处理所有事情时遇到了困难。
如果我仅向您显示配置的当前位置,这将更加容易:
.babelrc
{
"presets": [
"env",
{
"targets": {
"node": "current"
}
},
"jest"
]
}
Run Code Online (Sandbox Code Playgroud)
package.json
{
"scripts": {
"test": "node --harmony-async-await node_modules/jest/bin/jest.js",
"start:local": "NODE_ENV=localhost npm run babel-node -- warpcore/server.js",
"start": "npm run babel-node -- warpcore/server.js",
"babel-node": "babel-node --presets=es2015,stage-2"
},
"dependencies": {
"babel-polyfill": "^6.23.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2018": "^1.0.0",
"babel-preset-stage-2": …
Run Code Online (Sandbox Code Playgroud) 所以我们有一个 Vue.js mixin,它是在单个组件中继承的。mixin 有一个由少数组件继承的模板,它可以正常工作。但是,我不知道如何使用 vue-test-utils 测试模板。
这是我正在做的事情的一个简化示例:
describe('MiMixin', () => {
let wrapper
wrapper = mount({
mixins: [MiMixin]
})
it('should set the mixin template as the markup', () => {
wrapper.find('.mi-component').trigger('click')
})
})
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到消息:
[vue-test-utils]: find did not return .mi-component, cannot call trigger() on empty Wrapper
Run Code Online (Sandbox Code Playgroud)
如果我向挂载的 Vue 组件添加渲染函数,它只会渲染我返回的任何标记(如预期)。但是,当没有 render 方法(因此也没有模板)时,组件的 html 是未定义的。
问题:
注意:模板似乎确实存在于 VueComponent 下的包装器中:
VueWrapper {
vnode: [Getter/Setter],
element: [Getter/Setter],
update: [Function: bound update],
options: { attachedToDocument: false },
version: 2.5,
vm: …
Run Code Online (Sandbox Code Playgroud) 我有个问题。当我运行Jest测试时,它无法解析带有 at ( @
) 符号的导入。我有一个错误:
FAIL src/App.test.js\n \xe2\x97\x8f Test suite failed to run\n\n Cannot find module '@/helpers/configureStore' from 'App.js'\n
Run Code Online (Sandbox Code Playgroud)\n\n我该如何解决这个错误?
\n我正在为 Kubernetes 部署创建Helm Chart (v3)。在deployment.yaml中我定义了一些环境变量
spec:
...
env:
- name: GRAPHITE_ENABLED
value: {{ .Values.env.graphiteEnabled }}
- name: GRAPHITE_HOSTNAME
value: {{ .Values.env.graphiteHostname }}
Run Code Online (Sandbox Code Playgroud)
并在values.yaml中指定这些环境变量的值
env:
graphiteEnabled: "false"
graphiteHostname: "localhost"
Run Code Online (Sandbox Code Playgroud)
使用此命令运行图表时
helm install --debug api-test ./rest-api
Run Code Online (Sandbox Code Playgroud)
导致以下错误:
错误:版本“v1beta1”中的部署无法作为部署处理:v1beta1.Deployment.Spec:v1beta1.DeploymentSpec.Template:v1.PodTemplateSpec.Spec:v1.PodSpec.Containers:[] v1.Container:v1.Container.Env :[]v1.EnvVar:v1.EnvVar.Value:ReadString:需要“或n,但找到f
我有这个本机应用程序运行良好,但突然出现此错误:
error: bundling failed: Error: Unable to resolve module `fs` from `node_modules/eslint/lib/cli-engine/cli-engine.js`: fs could not be found within the project.
Run Code Online (Sandbox Code Playgroud)
我第一次拿到它时,我只是在测试这个应用程序,做我一整天都在做的事情,没有什么新鲜事,没有什么异常。现在我什至无法在我的设备上启动该应用程序。
我用这个脚本启动应用程序:yarn start-fresh
从我的 package.json:
"start-fresh": "cd android/ && ./gradlew clean && cd .. && rm -rf node_modules/ && yarn install && react-native start --reset-cache"
Run Code Online (Sandbox Code Playgroud)
然后在一个新的终端选项卡中,我执行yarn android
. 它在第二个选项卡中加载了所有内容,但是当我返回到第一个选项卡(我运行的位置yarn start-fresh
)时,它加载了一些东西,但随后出现错误。我不记得安装任何新软件包或更新软件包或类似的东西......
我尝试在线搜索解决方案,但找不到任何有用的信息。另外,在错误之后我有这个列表:
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules: rm -rf node_modules and run yarn …
Run Code Online (Sandbox Code Playgroud) 所以目前我遇到了autoprefixer的麻烦.
我已经将postcss-cli和autoprefixer下载到--save-dev和-g
当我运行这样的命令时:
postcss ../../../htdocs/css/workflow/homepage-announcements.css -o ../../../htdocs/css/workflow/homepage-announcements.css
Run Code Online (Sandbox Code Playgroud)
输出正常工作:
✔完成../../../htdocs/css/workflow/homepage-announcements.css(25ms)
现在我已经使用--use autoprefixer
了错误.下面的命令.
postcss --use autoprefixer ../../../htdocs/css/workflow/homepage-announcements.css -o ../../../htdocs/css/workflow/homepage-announcements.css
Run Code Online (Sandbox Code Playgroud)
错误信息:
✖插件错误:找不到模块'../../../htdocs/css/workflow/homepage-announcements.css'
我已经尝试了一切,仍然没有解决方案:(
{
"name": "homepage-announcements",
"version": "2.0.0",
"description": "Homepage announcements",
"main": "js/Default.js",
"dependencies": {
"react": "^15.4.2"
},
"devDependencies": {
"autoprefixer": "^6.7.7",
"ava": "^0.18.2",
"babel-loader": "^6.4.1",
"eslint": "^3.19.0",
"node-sass": "^4.5.2",
"postcss": "^5.2.16",
"postcss-cli": "^3.1.1",
"webpack": "^2.3.3",
"xo": "^0.18.1"
},
"scripts": {
"build": "webpack -p && npm run sass && npm run css",
"sass": "node-sass scss/default.scss ../../../htdocs/css/workflow/homepage-announcements.css --output-style compressed && npm run …
Run Code Online (Sandbox Code Playgroud) jestjs ×4
javascript ×2
autoprefixer ×1
babel ×1
babel-node ×1
enzyme ×1
eslint ×1
node.js ×1
npm ×1
postcss-cli ×1
react-native ×1
reactjs ×1
vue-mixin ×1
vue.js ×1
webpack ×1
yarnpkg ×1